题意:
字母相同,且大小写相同叫一次”YAY”
字母相同,大小写不同叫一次”WHOOP”
输出
最大YAY的个数,和最大YAY的个数的情况下,WHOOP的个数。
解析:
将用过的字符串标记一下,最后进行统计,详见代码。
AC代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
char s[N], t[N];
int A, B;
int cnt[256], cnt2[256];
int main() {
while(scanf("%s%s", s, t) != EOF) {
A = B = 0;
memset(cnt, 0, sizeof(cnt));
memset(cnt2, 0, sizeof(cnt2));
int len = strlen(s), len2 = strlen(t);
for(int i = 0; i < len; i++)
cnt[s[i]]++;
for(int i = 0; i < len2; i++)
cnt2[t[i]]++;
//统计A
int MIN;
for(char ch = 'a'; ch <= 'z'; ch++) {
MIN = min(cnt[ch], cnt2[ch]);
cnt[ch] -= MIN;
cnt2[ch] -= MIN;
A += MIN;
}
for(char ch = 'A'; ch <= 'Z'; ch++) {
MIN = min(cnt[ch], cnt2[ch]);
cnt[ch] -= MIN;
cnt2[ch] -= MIN;
A += MIN;
}
//统计B
for(char i = 'a', j = 'A'; i <= 'z'; i++, j++) {
B += min(cnt[i], cnt2[j]);
}
for(char i = 'A', j = 'a'; i <= 'Z'; i++, j++) {
B += min(cnt[i], cnt2[j]);
}
printf("%d %d\n", A, B);
}
return 0;
}