ZOJ 3603 Draw Something Cheat


テーマリンク:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3603
タイトル:
Draw Something Cheat
Time Limit: 2 Seconds     
メモリLimit: 65536 KB
Have you playd Draw SomethingIt's currently one of the hottest social drawingg 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.The n your friend will be asked the word is,givent the picture have drawn.The following wingfigur pital stres stration tyle stres.
ZOJ 3603 Draw Something Cheat_第1张图片
As You see,when gessing a word you will be given the picture and 12 letters.You must pick some of thers letters to form a word that the picture.Each letter can onlybe used onece.It is a lot of funt fredbut unfortunary some drawings from your friend are totally incompprehensible.After several times of becomping mad by the drawings,you find a way to cheat in the game.
In this game,letters not included in the corect answer are randomly generanted.If you cannot find the corect answer when gessing,you can write down all the letters and restart the game.The n you would find some of these letters ar are changed.Of course these change.will never appar in the answer.By eliminating thers letters.ore the ars.ore the the ars.ore.ore.ore.ore.ore.ore.ore.ore.ore.ore.ore.ore the the.Of course the
So In this proble,you need to write a program to autmate the checting process.Gven N stings of letters to the same picture,you need to eliminate as many letters as possible,and output the remaning letters.
Input
The re 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.The n N LINE.Each line is a string of exactly 12 up percase letters、indicating the candidate letters in one gess.It is ggated that the answer has at 1 letter and has no more 12 letters.
Output
For each test case,output the remaning 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
問題を解く:
   いくつかの文字列を与えます.答えは毎回残した文字に含まれていますので、これらの文字列のすべての共通文字を求めます.注意してください.各文字は何回も現れます.
コード:
#include <iostream>
#include <string>
#include <cstring>
int store[26],tmp[26];
using namespace std;
int main()
{
	int n,t;
	cin>>t;
	string s;
	while(t--)
	{
		memset(store,0,sizeof(store));
	   cin>>n;
	   cin>>s;
	   for(int i=0;i<s.length();i++)//         
	   {
   	      store[s[i]-'A']++;	
   	   }
	   for(int i=1;i<n;i++)
	   {
	   	  for(int j=0;j<26;j++)//      
		  tmp[j]=store[j]; 
   		  cin>>s;
   		  for(int j=0;j<s.length();j++)
   		  {
  		   	if(tmp[s[j]-'A'])//      
  		   	tmp[s[j]-'A']--;
          }
          for(int j=0;j<26;j++)//     ,       
          {
          	store[j]=store[j]-tmp[j];
          }
   	   }
   	   for(int i=0;i<26;i++)
   	   {
   	   	 for(int j=0;j<store[i];j++)
   	   	 cout<<char(i+'A');
   	   }
   	   cout<<endl;
	}
	return 0;
}