代码如下:#include<iostream>using namespace std;int main(){int i[1000],j,a=0,b=0,c=0,r=0;for(j=0;j<1000;j++){i[j]=0;}//初始化数组,否则会出错j=0;while(!(i[j-1]==-1)){cin>>i[j];j++;}//输入选票for(j=0;j<1000;j++){if(i[j]>0&&i[j]<4){r++;}} //统计全班人数for(j=0;j<r;j++){if(i[j]==1){a++;}if(i[j]==2){b++;}if(i[j]==3){c++;}}//统计得票数cout<<"A="<<a<<endl;cout<<"B="<<b<<endl;cout<<"C="<<c<<endl;if(a>(r/2)){cout<<"A-yes";}else if(b>(r/2)){cout<<"B-yes";}else if(c>(r/2)){cout<<"C-yes";}else{cout<<"all-no";}}运行结果