题意:给定两个字符串,然后从第二个中找和第一个相同的,如果大小写相同,那么就是YAY,如果大小写不同,那就是WHOOPS。YAY要尽量多,其次WHOOPS也要尽量多。
析:这个题并不难,难在读题懂题意。首先把两个字符串的的每个字符存起来,然后,先扫一遍,把所有的能YAY的都选出来,剩下的再尽量先WHOOPS。
代码如下:
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <set> #include <cstring> #include <cmath> #include <map> #include <cctype> using namespace std; const int maxn = 1000 + 5; map<char, int> mp1; map<char, int> mp2; string s1, s2; int main(){ cin >> s1 >> s2; for(int i = 0; i < s1.size(); ++i) ++mp1[s1[i]]; for(int i = 0; i < s2.size(); ++i) ++mp2[s2[i]]; int cnt1 = 0, cnt2 = 0; for(int i = 0; i < 26; ++i){ if(mp1[i+'a'] >= mp2[i+'a']){ cnt1 += mp2[i+'a']; mp1[i+'a'] -= mp2[i+'a']; mp2[i+'a'] = 0; }else{ cnt1 += mp1[i+'a']; mp2[i+'a'] -= mp1[i+'a']; mp1[i+'a'] = 0; } if(mp1[i+'A'] >= mp2[i+'A']){ cnt1 += mp2[i+'A']; mp1[i+'A'] -= mp2[i+'A']; mp2[i+'A'] = 0; }else{ cnt1 += mp1[i+'A']; mp2[i+'A'] -= mp1[i+'A']; mp1[i+'A'] = 0; } } for(int i = 0; i < 26; ++i){ if(mp1[i+'a']) cnt2 += min(mp1[i+'a'], mp2[i+'A']); if(mp1[i+'A']) cnt2 += min(mp1[i+'A'], mp2[i+'a']); } printf("%d %d\n", cnt1, cnt2); return 0; }