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 |
C++参考#include<iostream> #include<stdlib.h> #include <string> #include <map> #include <vector> #include <algorithm> using namespace std; typedef pair<char, int> PAIR; bool cmp_by_value(const PAIR& x, const PAIR& y) { return abs(x.second) > abs(y.second); } int main(void) { int n; string s[3]; map<char, int> coin; cin >> n; while (n-- > 0) { coin.clear(); for (int m = 0; m < 3; m++) { for (int i = 0; i < 3; i++) cin >> s[i]; if (s[2] == "even") { for (int i = 0; i < s[0].length(); i++) { coin[s[0][i]] = 5; coin[s[1][i]] = 5; } } else if (s[2] == "up") { for (int i = 0; i < s[0].length(); i++) { if (coin[s[0][i]] != 5) coin[s[0][i]] += 1; if (coin[s[1][i]] != 5) coin[s[1][i]] -= 1; } } else if (s[2] == "down") { for (int i = 0; i < s[0].length(); i++) { if (coin[s[0][i]] != 5) coin[s[0][i]] -= 1; if (coin[s[1][i]] != 5) coin[s[1][i]] += 1; } } } vector<PAIR> coin_vec(coin.begin(), coin.end()); for (int i = 0; i != coin_vec.size(); ++i) if (coin_vec[i].second == 5) coin_vec[i].second = 0; sort(coin_vec.begin(), coin_vec.end(), cmp_by_value); if (coin_vec.begin()->second > 0) cout << coin_vec.begin()->first << " is the counterfeit coin and it is heavy." << endl; else cout << coin_vec.begin()->first << " is the counterfeit coin and it is light." << 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