1.题目描述:点击打开链接
2.解题思路:本题是一道模拟题,要求模拟一个解密的过程,练习这么久第一次做模拟题1Y了,内心还是很激动的~。只需要根据题意,记录* 所在的位置即可,然后每次都是先解密,后顺时针旋转90度。把每次解密的信息放到一个vector里,接下来就是连接它们,得到解密后的字符串,在map中查找这些单词是否存在即可。如果都存在,就把这条解密信息放到ans中,最后对ans排序,输出ans[0]就是答案。
3.代码:
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<algorithm>
#include<cassert>
#include<string>
#include<sstream>
#include<set>
#include<bitset>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<deque>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<functional>
using namespace std;
#define me(s) memset(s,0,sizeof(s))
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair <int, int> P;
const int N=55;
char s[N][N];
vector<P>pos;
vector<string>mes;
map<string,int>words;
int n;
void rotate()//将每个方格旋转90度
{
int len=pos.size();
for(int i=0;i<len;i++)
{
int x=pos[i].first,y=pos[i].second;
pos[i]=P(y,n-1-x);
}
sort(pos.begin(),pos.end());
}
void decrypt(int dir)//解密
{
int len=pos.size();
string tmp="";
for(int i=0;i<len;i++)
{
int x=pos[i].first,y=pos[i].second;
tmp+=(isalpha(s[x][y]))?s[x][y]:' ';
}
mes.push_back(tmp);
rotate();
}
int main()
{
int T;
scanf("%d",&T);
for(int kase=1;kase<=T;kase++)
{
scanf("%d",&n);
me(s);
pos.clear();mes.clear();words.clear();
for(int i=0;i<n;i++)
scanf("%s",s[i]);
char tmp[N];
for(int i=0;i<n;i++)
{
scanf("%s",tmp);
for(int j=0;j<n;j++)
if(tmp[j]=='*')
pos.push_back(P(i,j));
}
int m;
scanf("%d",&m);
string tp;
for(int i=0;i<m;i++)
{
cin>>tp;
words[tp]=i;
}
printf("Case #%d: ",kase);
for(int i=0;i<4;i++)
decrypt(i);
vector<string>ans;
for(int i=0;i<4;i++)
{
string s=mes[i]+mes[(i+1)%4]+mes[(i+2)%4]+mes[(i+3)%4];//连接信息
int p=0,st=0;
string ts="",tc;
stringstream ss(s);
int first=1;
int ok=1;
while(ss>>tc)
{
if(!words.count(tc)){ok=0;break;}
if(first)first=0;
else ts+=' ';
ts+=tc;
}
if(ok)ans.push_back(ts);//每个单词都找到了,存到ans中
}
if(!ans.empty())
{
sort(ans.begin(),ans.end());
cout<<ans[0]<<endl;
}
else puts("FAIL TO DECRYPT");
}
}