谁想到了用map做?
2025-08-13 17:06:12
发布于:浙江
8阅读
0回复
0点赞
我这用的是map,下标设置成string类型直接访问扑克牌数量,再检查是否重复(去重)。
代码
#include <cstdio>
#include <iostream>
#include <map>
std::map<std::string,int> a;
int main(){
int n;
scanf("%d",&n);
int ans = n;
while(n--){
std::string st;
st.resize(2);
scanf("%s",&st[0]);
if(a[st]==0){
a[st]++;
}else{
ans--;
}
}
printf("%d\n",52-ans);
return 0;
}
这里空空如也
有帮助,赞一个