标签:size logs out ann people correct trie cat flip
The first line contains an integer T(1 <= T <= 100), indicating the number of test cases.
Each test case contains several lines.
The first line contains an even integer N(2 <= N <= 50), indicating the size of the matrix.
The following N lines each contains exactly N characters, reresenting the message matrix. The message only contains lowercase letters and periods(‘.‘), where periods represent the white spaces.
You can assume the matrix contains at least one letter.
The followingN lines each containsN characters, representing the mask matrix. The asterisk(‘*‘) represents a hole, and period(‘.‘) otherwise. The next line contains an integer M(1 <= M <= 100), the number of words he knew.
Then the following M lines each contains a string represents a word. The words only contain lowercase letters, and its length will not exceed 20.
Output
For each test case in the input, print one line: "Case #X: Y", where X is the test case number (starting with 1) and Y is Isabella‘s message.
If Steve cannot understand the message, just print the Y as "FAIL TO DECRYPT".
题目大意:给你一个n*n的格子,格子里面有字母和空格,然后你拿挡板去截取字母,然后问你是否能够还原。
具体思路:这么小的数据范围,模拟一下就好了,非常简单我才不会说我PE了2发呢
单词有没有出现过可以用map判(记得要清空),答案什么的用string非常方便
要注意的还有答案的最后不能有空格否则会PE
字典序最小的要求只要把可行的答案扔到数组里,sort一下就好了
AC代码
#include<bits/stdc++.h> using namespace std; int i,j,n,T,m,t; char mp[1000][1000],key[1000][1000],key2[1000][1000]; string word[200]; string hhh[10],ans[10],hhhh,tot; map<string,bool> bo; bool ok; void zhuan() { for (int i=1;i<=n;i++)for (j=1;j<=n;j++)key2[i][j]=key[i][j]; for (int i=1;i<=n;i++)for (j=1;j<=n;j++)key[i][j]=key2[j][n-i+1]; } int main() { scanf("%d",&T); while (T--) { t++,bo.clear(),scanf("%d",&n); for (i=1;i<=n;i++)scanf("%s",mp[i]+1); for (i=1;i<=n;i++)scanf("%s",key[i]+1); scanf("%d",&m); for (i=1;i<=m;i++)cin>>word[i],bo[word[i]]=true; for (i=1;i<=4;i++) { zhuan(),zhuan(),zhuan();//?òo???°?Dy×a·??ò??·′á?,·′?y×aèy′??íoíòa?óò??ùá? hhh[i]=""; for (int x=1;x<=n;x++) for (int y=1;y<=n;y++) if(key[x][y]==‘*‘) if(mp[x][y]!=‘.‘) hhh[i]=hhh[i]+mp[x][y]; else hhh[i]=hhh[i]+" "; } for (i=1;i<=4;i++)ans[i]=""; int anstop=0; for (i=1;i<=4;i++) { tot=hhh[1]+hhh[2]+hhh[3]+hhh[4],ok=true,anstop++,ans[anstop]=""; for (j=0;j<tot.length();j++) { string wo=""; while (tot[j]==‘ ‘&&j<tot.length())j++; while (tot[j]!=‘ ‘&&j<tot.length())wo=wo+tot[j],j++; if(!bo[wo]&&wo!="") { ok=false; break; } ans[anstop]=ans[anstop]+wo+" "; } if(!ok)anstop--; hhhh=hhh[1],hhh[1]=hhh[2],hhh[2]=hhh[3],hhh[3]=hhh[4],hhh[4]=hhhh; } printf("Case #%d: ",t); if(anstop) { sort(ans+1,ans+anstop+1); string::iterator it=ans[1].end()-1; while (*it==‘ ‘)ans[1].erase(it),it=ans[1].end()-1; cout<<ans[1]<<endl; }else puts("FAIL TO DECRYPT"); } return 0; }
标签:size logs out ann people correct trie cat flip
原文地址:http://www.cnblogs.com/Orange-User/p/7794518.html