#include "iostream" int main() { int length; int Idcou[3]={0,0,0};//计数器初始化为0 int ID[3]={0,0,0}; //水王id初始化为0 printf("请输入发帖的数量:"); scanf("%d",&length); int * shuiwang=new int [length]; printf("请输入所有发帖人的ID:"); for(int j=0;j<length;j++)//输入id { scanf("%d",&shuiwang[j]); } for(int i=0;i<length;i++)//找水王 { if(Idcou[0]==0 && shuiwang[i]!=ID[1] && shuiwang[i]!=ID[2]) { Idcou[0]=1; ID[0]=shuiwang[i]; } else if(Idcou[1]==0 &&shuiwang[i]!=ID[0] && shuiwang[i]!=ID[2]) { Idcou[1]=1; ID[1]=shuiwang[i]; } else if(Idcou[2]==0 &&shuiwang[i]!=ID[0] && shuiwang[i]!=ID[1]) { Idcou[2]=1; ID[2]=shuiwang[i]; } else if(shuiwang[i]!=ID[0] && shuiwang[i]!=ID[1] && shuiwang[i]!=ID[2]) { Idcou[0]--; Idcou[1]--; Idcou[2]--; } else if(shuiwang[i]==ID[0]) { Idcou[0]++; } else if(shuiwang[i]==ID[1]) { Idcou[1]++; } else if(shuiwang[i]==ID[2]) { Idcou[2]++; } } printf("三个水王的ID是:\n"); printf("%d\t%d\t%d\t\n",ID[0],ID[1],ID[2]); return 0; }
时间: 2024-12-13 10:41:19