时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
题目描述
牛村正在进行村长选举,投票人一人一票,牛可乐是候选人A(投票代号为1)、牛能是候选人B(投票代号为2)和牛妹是候选人C(投票代号为3),其他投票代号无效。
投票列表用以-1表示结束,请分别统计出他们的得票数。谁的得票超过全部投票人数的半数,就输出谁当选为村长,如“A-yes”表示A当选,全部不过半数,输出“all-NO”。
输入描述:
输入一行,若干个整数,以-1结尾
输出描述:
输出五行,前三行表示三个候选人的表票数,然后是总的有效票数,最后一行表示选举结果。
示例1
输入
1 1 3 2 1 3 2 1 3 3 1 2 4 1 4 1 2 1 2 1 1 -1
输出
A=10
B=5
C=4
Tot=19
all-NO
#include<iostream>
using namespace std;
int main()
{
int A,B,C;
A=B=C=0;
int k=0,n;
cin>>n;
while(n!=-1)
{
k++;
if(n==1)
A++;
else if(n==2)
B++;
else if(n==3)
C++;
cin>>n;
}
cout<<"A="<<A<<endl<<"B="<<B<<endl<<"C="<<C<<endl;
cout<<"Tot="<<A+B+C<<endl;
if(A>k/2)
cout<<"A-yes"<<endl;
else if(B>(k)/2)
cout<<"B-yes"<<endl;
else if(C>(k)/2)
cout<<"C-yes"<<endl;
else cout<<"all-NO"<<endl;
return 0;
}