题解 | #扑克牌大小#
扑克牌大小
https://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb
打卡
#include <iostream> #include<algorithm> #include <string> #include <vector> #include<sstream> using namespace std; void cmp(vector<string>a, vector<string>b) { vector<string>table = { "3","4","5","6","7","8","9","10","J","Q","K","A","2","joker","JOKER" }; int pa = a.size(), pb = b.size(), da = find(table.begin(), table.end(), a[0]) - table.begin(), db = find(table.begin(), table.end(), b[0]) - table.begin(); if (pa == 2 && a[0] == "joker" || pb == 2 && b[0] == "joker") { cout << "joker" << ' ' << "JOKER" << endl; } else if (pa == pb) { if (da > db) { for (int i = 0; i < pa; i++) cout << a[i] << ' '; } if (da < db) { for (int i = 0; i < pb; i++) cout << b[i] << ' '; } } else { if (pa == 4) { for (int i = 0; i < pa; i++) cout << a[0] << ' '; } else if (pb == 4) { for (int i = 0; i < pb; i++) cout << b[0] << ' '; } else cout << "ERROR"; } } int main() { vector<string>a, b; string s, s1, s2; stringstream ss; getline(cin, s); int pos = s.find('-'); s1 = s.substr(0, pos); s2 = s.substr(pos + 1); ss << s1; while (ss>>s) { a.push_back(s); } ss.clear(); ss << s2; while (ss >> s) { b.push_back(s); } cmp(a, b); return 0; }