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 |
分享代码#include <iostream> #include <string> #include <math.h> using namespace std; typedef struct node { int used; int weight; }Node; int main() { int N,i,n,w,used,weight,tempused,tempweight; Node map[3][12]; string left; string right; string comp; char coin; cin >> N; while(N-->0) { memset(map,0,sizeof(Node)*3*12); n = 0; while(n<3) { cin >> left >> right >> comp; w = comp.at(0)=='e' ? 0 : (comp.at(0)=='u' ? -1 : 1); for(i=0;i<left.length();i++) { map[n][left.at(i)-'A'].used = 1; map[n][left.at(i)-'A'].weight = w * (-1); map[n][right.at(i)-'A'].used = 1; map[n][right.at(i)-'A'].weight = w; } n++; } used = weight = 0; for(i=0;i<12;i++) { tempused = map[0][i].used + map[1][i].used + map[2][i].used; tempweight = map[0][i].weight + map[1][i].weight + map[2][i].weight; //cout << (char)(i+'A') << ':' << used << ',' << weight << ' ' << (used!=0&&used==abs(weight)?'*':' ') << endl; if(tempused==0 || tempused!=abs(tempweight)) continue; else if(tempused > used) { used = tempused; weight = tempweight; coin = (char)(i+'A'); } } cout << coin << " is the counterfeit coin and it is " << (weight<0?"light":"heavy") << ".\n"; } 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