Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
是不是因为getline()用的不对才WA的呢?#include <iostream> #include <fstream> #include <string> #include <cstdlib> using namespace std; int main() { int n,m; int i,j; string candidate[21]; string party[21]; int votes[21]; string ballot; cin >> n; cin.ignore(); for (i = 0; i < n; i++) { getline(cin,candidate[i]); getline(cin,party[i]); votes[i] = 0; } cin >> m; cin.ignore(); for ( i = 0; i < m; i++) { getline(cin,ballot); for (j = 0; j < n; j++) { if (ballot == candidate[j]) { votes[j]++; break; } } } bool flag = true; int nmax = 0; int index; for( i = 0; i < n ;i++) { if (votes[i] != votes[0]) flag = false; if ( votes[i] > nmax) { nmax = votes[i]; index = i; } } if (flag) { cout << "tie" << endl; } else { cout << party[index] << endl; } system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator