Concatenation of Languages UVA - 10887

原题链接

考察:STL

用STL去重即可,输入非常毒,存在空白字符串,我们要用getline输入,否则字符串会读到m和n的数字

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 set<string> st;
 4 vector<string> a,b;
 5 int main()
 6 {
 7 //    freopen("in.txt","r",stdin);
 8 //    freopen("out.txt","w",stdout);
 9     int t,kcase=0;
10     scanf("%d",&t);
11     while(t--){
12         st.clear(); a.clear(); b.clear();
13         printf("Case %d: ",++kcase);
14         int n,m;
15         scanf("%d%d",&n,&m);
16         getchar();
17         for(int i=1;i<=n;i++)
18         {
19             string s; getline(cin,s);
20             a.push_back(s);
21         }
22         for(int i=1;i<=m;i++)
23         {
24             string s; getline(cin,s);
25             b.push_back(s);
26         }
27         for(int i=0;i<=n-1;i++)
28             for(int j=0;j<=m-1;j++)
29                 st.insert(a[i]+b[j]);
30         printf("%d\n",st.size());
31     }
32     return 0;
33 } 

 

posted @ 2021-01-07 18:49  acmloser  阅读(109)  评论(0编辑  收藏  举报