题意:有六种颜色宝石,每种宝石对应一种能力。你现在已经有N个颜色宝石了,问你还缺少哪几个能力的宝石?
思路:用map颜色映射一下能力,暴力查找看缺少哪几个。
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
map<string, string> mp;
set<string> s;
string ans[10];
int main()
{
mp["purple"] = "Power"; mp["green"] = "Time"; mp["blue"] = "Space";
mp["orange"] = "Soul"; mp["red"] = "Reality"; mp["yellow"] = "Mind";
int n; scanf("%d", &n);
string str;
for (int i = 0; i < n; i++) cin >> str, s.insert(str);
int cnt = 0;
for (auto i: mp)
{
if (!s.count(i.first)) ans[cnt++] = i.second;
}
cout << cnt << endl;
for (int i = 0; i < cnt; i++) cout << ans[i] << endl;
return 0;
}
/*
0
*/
本文介绍了一种使用C++编程语言解决寻找缺失宝石能力的问题的方法。通过构建颜色到能力的映射,并遍历已有的宝石颜色集合来确定缺失的能力。
1153

被折叠的 条评论
为什么被折叠?



