题解(欢迎指正)
2025-08-20 18:20:37
发布于:浙江
4阅读
0回复
0点赞
我的方法比较麻烦,if大法,把字母牌(例如A,T,)通过if,再通过一个bool类型的vis数组进行标记,标记是否出现,再在最后通过vis数组进行输出完成
以下是我的代码:
#include <bits/stdc++.h>
using namespace std;
int n, cnt = 0;
bool vis[9][18] = {false};
string s;
int main () {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
if (s[0] == 'D') {
int x = 1;
if (s[1] == 'A') {
vis[x][1] = true;
}
else if (s[1] == 'T') {
vis[x][10] = true;
}
else if (s[1] == 'J') {
vis[x][11] = true;
}
else if (s[1] == 'Q') {
vis[x][12] = true;
}
else if (s[1] == 'K') {
vis[x][13] = true;
}
else {
int a = s[1] - '0';
vis[x][a] = true;
}
}
else if (s[0] == 'C') {
int x = 2;
if (s[1] == 'A') {
vis[x][1] = true;
}
else if (s[1] == 'T') {
vis[x][10] = true;
}
else if (s[1] == 'J') {
vis[x][11] = true;
}
else if (s[1] == 'Q') {
vis[x][12] = true;
}
else if (s[1] == 'K') {
vis[x][13] = true;
}
else {
int a = s[1] - '0';
vis[x][a] = true;
}
}
else if (s[0] == 'H') {
int x = 3;
if (s[1] == 'A') {
vis[x][1] = true;
}
else if (s[1] == 'T') {
vis[x][10] = true;
}
else if (s[1] == 'J') {
vis[x][11] = true;
}
else if (s[1] == 'Q') {
vis[x][12] = true;
}
else if (s[1] == 'K') {
vis[x][13] = true;
}
else {
int a = s[1] - '0';
vis[x][a] = true;
}
}
else {
int x = 4;
if (s[1] == 'A') {
vis[x][1] = true;
}
else if (s[1] == 'T') {
vis[x][10] = true;
}
else if (s[1] == 'J') {
vis[x][11] = true;
}
else if (s[1] == 'Q') {
vis[x][12] = true;
}
else if (s[1] == 'K') {
vis[x][13] = true;
}
else {
int a = s[1] - '0';
vis[x][a] = true;
}
}
}
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= 13; j++) {
if (vis[i][j]) {
cnt++;
}
}
}
cout << 52 - cnt;
return 0;
}
全部评论 2
全程复制粘贴。。。
2025-08-20 来自 浙江
1用switch也可以……
#include <bits/stdc++.h> using namespace std; int main() { int n, record[4][13] = {}, cnt = 0; cin >> n; for(int i = 0; i < n; i++) { char num, flower; int num_t, flower_t; cin >> flower >> num; num_t = num - 49; switch(num) { case 'A':num_t = 0;break; case 'T':num_t = 9;break; case 'J':num_t = 10;break; case 'Q':num_t = 11;break; case 'K':num_t = 12;break; } switch(flower) { case 'D':flower_t = 0;break; case 'C':flower_t = 1;break; case 'H':flower_t = 2;break; case 'S':flower_t = 3;break; } record[flower_t][num_t] = 1; } for(int i = 0; i < 4; i++) { for(int j = 0; j < 13; j++) { if(record[i][j] != 1) cnt++; } } cout << cnt; return 0; }
2025-08-22 来自 浙江
0确实可以哈,主要是是考试的时候做的,没往深了想
6天前 来自 浙江
0
有帮助,赞一个