解题思路:
注意事项:
参考代码:
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <map> #include <string> #include <stdio.h> #include <algorithm> using namespace std; string cards[5]; map<char, int> valMap; map<char, int> colMap; bool cmp(string a, string b) { if (valMap[a[0]] < valMap[b[0]]) return true; else if (valMap[a[0]] == valMap[b[0]]) { if (colMap[a[1]] < colMap[b[1]]) return true; else return false; } else return false; } int main() { for (int i = 0; i < 5; i++) { char c1, c2; c1 = getchar(); c2 = getchar(); cards[i] += c1; cards[i] += c2; } for (int i = 2; i <= 10; i++) valMap[i + '0'] = i; valMap['J'] = 11; valMap['Q'] = 12; valMap['K'] = 13; valMap['A'] = 14; colMap['d'] = 0; colMap['c'] = 1; colMap['h'] = 2; colMap['s'] = 3; sort(cards, cards + 5, cmp); for (int i = 0; i < 5; i++) cout << cards[i] << " "; return 0; }
0.0分
2 人评分
三进制小数 (C++代码)(第11位大于1.5才能进位)浏览:1205 |
C二级辅导-等差数列 (C语言代码)浏览:630 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:674 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:553 |
c primer plus 第十二章 12.1小节浏览:400 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:909 |
printf基础练习2 (C语言代码)浏览:826 |
三角形 (C语言代码)浏览:965 |
Hello, world! (C++代码)浏览:1779 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:590 |