题意:把两次给出的单词拼接在一起, 输出拼接后一共几种单词。
题解:用map水过。
#include <stdio.h>
#include <string.h>
#include <map>
#include <string>
#include <iostream>
using namespace std;
const int N = 1005;
string str1[N], str2[N];
map<string, int> m;
int main() {
int t, n1, n2, cases = 1, ans;
scanf("%d", &t);
while (t--) {
m.clear();
ans = 0;
scanf("%d%d", &n1, &n2);
getchar();
for (int i = 0; i < n1; i++)
getline(cin, str1[i]);
for (int i = 0; i < n2; i++)
getline(cin, str2[i]);
for (int i = 0; i < n1; i++) {
for (int j = 0; j < n2; j++) {
string temp = str1[i];
temp += str2[j];
if (!m[temp]) {
m[temp] = 1;
ans++;
}
}
}
printf("Case %d: %d\n", cases++, ans);
}
return 0;
}