[ACM_模拟] ACM - Draw Something Cheat [n个长12的大写字母串,找出交集,按字母序输出]

简介:


 

Description

Have you played Draw Something? It's currently one of the hottest social drawing games on Apple iOS and Android Devices! In this game, you and your friend play in turn. You need to pick a word and draw a picture for this word. Then your friend will be asked what the word is, given the picture you have drawn. The following figure illustrates a typical scenario in guessing the word.

word guessing in draw something

As you see, when guessing a word you will be given the picture and 12 letters. You must pick some of these letters to form a word that matches the picture. Each letter can only be used once. It is a lot of fun if your friend is a talented painter, but unfortunately some drawings from your friend are totally incomprehensible. After several times of becoming mad by the drawings, you find a way to cheat in the game.

In this game, letters not included in the correct answer are randomly generated. If you cannot find the correct answer when guessing, you can write down all the letters and restart the game. Then you would find some of these letters are changed. Of course these changed letters will never appear in the answer. By eliminating these letters you are a step closer to the answer.

So In this problem, you need to write a program to automate the cheating process. Given N strings of letters to the same picture, you need to eliminate as many letters as possible, and output the remaining letters.

Input

There are multiple test cases. The first line of the input is an integer T ≈ 1000 indicating the number of test cases.

Each test case begins with a positive integer N ≤ 20 indicating the number of times you have entered the game. Then N lines follow. Each line is a string of exactly 12 uppercase letters, indicating the candidate letters in one guess. It is guaranteed that the answer has at least 1 letter and has no more than 12 letters.

Output

For each test case, output the remaining letters in alphabet order after the process described above. One line for each test case.

Sample Input

2
2
ABCDEFGHIJKL
ABCDEFGHIJKL
2
SAWBCVUXDTPN
ZQTLFJYRCGAK

Sample Output

ABCDEFGHIJKL
ACT


题目大意:第一个T表示有T组,每组一个n表示接下来n个长为12的string,求这些string的交集并安字典序输出。
解题思路:用num_ABC[26]表示交集,用temp_num[26]表示每个string的情况,这里26表示26个大写字母,数组的值表示含该字母的数量

复制代码
 1 #include<iostream>
 2 #include<string.h>
 3 #include<cstring>
 4 #include<string>
 5 using namespace std;
 6 int main(){
 7     int T;cin>>T;
 8     while(T--){
 9         int num_ABC[26];//交集
10         int temp_num[26];//每个string的情况
11         string str;int n;
12         cin>>n;
13         for(int i=0;i<26;i++)num_ABC[i]=299999;//初始化很大的
14         while(n--){//n个string过来
15             cin>>str;
16             memset(temp_num,0,sizeof(temp_num));
17             for(int i=0;i<12;i++){
18                 temp_num[str[i]-'A']++;
19             }//统计
20             for(int i=0;i<26;i++)if(num_ABC[i]>temp_num[i]){
21                 num_ABC[i]=temp_num[i];
22             }//更新交集
23         }
24         for(int i=0;i<26;i++){//输出
25             while(num_ABC[i]--){
26                 cout<<(char)(i+'A');
27             }
28         }cout<<'\n';
29     }return 0;
30 }
复制代码
相关文章
|
6月前
【题解】NowCoder BC149 简写单词
【题解】NowCoder BC149 简写单词
55 15
|
算法 C语言
(c语言)将一句话的单词进行倒置,标点不倒置(i like beijing.)
(c语言)将一句话的单词进行倒置,标点不倒置(i like beijing.)
174 0
|
7月前
|
Java Go C++
Golang每日一练(leetDay0107) 去除重复字母、最大单词长度乘积
Golang每日一练(leetDay0107) 去除重复字母、最大单词长度乘积
54 0
Golang每日一练(leetDay0107) 去除重复字母、最大单词长度乘积
|
7月前
|
Java 容器
java字符串练习题2、反向输出英文字符串
java字符串练习题2、反向输出英文字符串
42 0
|
算法 Java 程序员
【手绘算法】力扣 3 无重复的最长字符串(Longest Substring Without Repeating Characters)
Hi,大家好,我是Tom。一个美术生转到Java开发的程序员。今天给大家分享的是力扣题第3题,无重复的最长字符串。在解题过程中,也会手写一些伪代码。当然,如果想要完整的源码的话,可以到我的个人主页简介中获取。 这道题呢属于中等难度,评估为四颗星,它的通过率只有39%。
91 0
|
存储 机器学习/深度学习 算法
acm拿国奖的第一关:数组和字符串
首先,集合里的元素类型不一定相同。 你可以将商品看作一个集合,也可以将整个商店看作一个集合,这个商店中有人或者其他物品也没有关系。
112 0
acm拿国奖的第一关:数组和字符串
|
算法 语音技术 Python
Python算法:Brute-Force算法查找字符串子串位置
Python算法:Brute-Force算法查找字符串子串位置
116 0
Python算法:Brute-Force算法查找字符串子串位置
|
算法 Java 索引
【算法】给定一个字符串 s 和一些长度相同的单词 words,串联所有单词的子串。要不要来试一试?
给定一个字符串 s 和一些长度相同的单词 words串联所有单词的子串
154 0
【算法】给定一个字符串 s 和一些长度相同的单词 words,串联所有单词的子串。要不要来试一试?
|
Python
Python经典编程习题100例:第17例:统计字符、数字、其他字符个数
Python经典编程习题100例:第17例:统计字符、数字、其他字符个数
121 0
|
机器学习/深度学习
LeetCode contest 190 5416. 检查单词是否为句中其他单词的前缀
LeetCode contest 190 5416. 检查单词是否为句中其他单词的前缀