2403. Voting
Description
A committee clerk is good at recording votes, but not so good at counting and figuring the outcome correctly. As a roll call vote proceeds, the clerk records votes as a sequence of letters, with one letter for every member of the committee:
Y means a yes vote
N means a no vote
P means present, but choosing not to vote
A indicates a member who was absent from the meeting
N means a no vote
P means present, but choosing not to vote
A indicates a member who was absent from the meeting
Your job is to take this recorded list of votes and determine the outcome.
Rules:
There must be a quorum. If at least half of the members were absent, respond "need quorum". Otherwise votes are counted. If there are more yes than no votes, respond "yes". If there are more no than yes votes, respond "no". If there are the same number of yes and no votes, respond "tie".
There must be a quorum. If at least half of the members were absent, respond "need quorum". Otherwise votes are counted. If there are more yes than no votes, respond "yes". If there are more no than yes votes, respond "no". If there are the same number of yes and no votes, respond "tie".
Input
The input contains of a series of votes, one per line, followed by a single line with the # character. Each vote consists entirely of the uppercase letters discussed above. Each vote will contain at least two letters and no more than 70 letters.
Output
For each vote, the output is one line with the correct choice "need quorum", "yes", "no" or "tie".
Sample Input
YNNAPYYNY YAYAYAYA PYPPNNYA YNNAA NYAAA #
Sample Output
yes need quorum tie no need quorum
Problem Source
每周一赛第四场
// source code of submission 963980, Zhongshan University Online Judge System
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
string str;
while (cin >> str)
{
if (str == "#")
return 0;
else
{
int len = str.length();
int a[4] = {0,0,0,0};
for(int i = 0;i < len; i++)
{
if(str[i] == 'Y')
a[0]++;
else if(str[i] == 'N')
a[1]++;
else if(str[i] == 'P')
a[2]++;
else if(str[i] == 'A')
a[3]++;
}
if (a[3] >= (double)len / 2)
cout << "need quorum" << endl;
else if (a[0] > a[1])
cout << "yes" << endl;
else if (a[0] < a[1])
cout << "no" << endl;
else if (a[0] == a[1])
cout << "tie" << endl;
}
}
return 0;
}