题目链接:http://write.blog.csdn.net/postedit
自我感觉比较麻烦
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<string>
#include<map>
using namespace std;
const int maxh=100+10;
const int maxe=100+10;
typedef struct Node
{
char s[maxh*maxh];
};
Node E[4];
char mode[maxh][maxh],mail[maxh][maxh];
int n,m,H[4];
bool cmp(Node a,Node b)
{
return strcmp(a.s,b.s)<0;
}
void take()
{
char s[maxh*maxh*4];
memset(s,0,sizeof(s));
int h=0,h1,h2,h3,num=0,l,e,flag,i,j;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(mode[i][j]==‘*‘)
{
s[h++]=mail[i][j];
num++;
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(mode[n-j-1][i]==‘*‘)
s[h++]=mail[i][j];
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(mode[n-1-i][n-1-j]==‘*‘)
s[h++]=mail[i][j];
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(mode[j][n-1-i]==‘*‘)
s[h++]=mail[i][j];
char ss[3][maxh*maxh];
memset(ss,0,sizeof(ss));
memset(E,0,sizeof(E));
for(i=num,h1=0;h1<h;h1++,i=(i+1)%h)
ss[0][h1]=s[i];
for(i=num+num,h2=0;h2<h;h2++,i=(i+1)%h)
ss[1][h2]=s[i];
for(h3=0,i=num+num+num;h3<h;h3++,i=(i+1)%h)
{
ss[2][h3]=s[i];
}
l=0;
while(s[l]==‘ ‘)l++;
while(s[h-1]==‘ ‘)h--;
int e1=0,e2=0;
for(i=l,j=0;i<h;i++)
{
if(s[i]==‘ ‘&&e1==0)
{
E[0].s[j++]=s[i];
e1=1;
}
else if(s[i]!=‘ ‘)
{
E[0].s[j++]=s[i];
e1=0;
}
}
l=0;
while(ss[0][l]==‘ ‘)l++;
while(ss[0][h1-1]==‘ ‘)h1--;
e1=0,e2=0;
for(i=l,j=0;i<h1;i++)
{
if(ss[0][i]==‘ ‘&&e1==0)
{
E[1].s[j++]=ss[0][i];
e1=1;
}
else if(ss[0][i]!=‘ ‘)
{
E[1].s[j++]=ss[0][i];
e1=0;
}
}
l=0;
while(ss[1][l]==‘ ‘)l++;
while(ss[1][h2-1]==‘ ‘)h2--;
e1=0,e2=0;
for(i=l,j=0;i<h2;i++)
{
if(ss[1][i]==‘ ‘&&e1==0)
{
E[2].s[j++]=ss[1][i];
e1=1;
}
else if(ss[1][i]!=‘ ‘)
{
E[2].s[j++]=ss[1][i];
e1=0;
}
}
l=0;
while(ss[2][l]==‘ ‘)l++;
while(ss[2][h3-1]==‘ ‘)h3--;
e1=0,e2=0;
for(i=l,j=0;i<h3;i++)
{
if(ss[2][i]==‘ ‘&&e1==0)
{
E[3].s[j++]=ss[2][i];
e1=1;
}
else if(ss[2][i]!=‘ ‘)
{
E[3].s[j++]=ss[2][i];
e1=0;
}
}
H[0]=h,H[1]=h1,H[2]=h2,H[3]=h3;
}
int main()
{
int T,t,i,j,flag,l;
char c[10000];
scanf("%d",&T);
for(t=1;t<=T;t++)
{
scanf("%d",&n);
memset(mail,0,sizeof(mail));
memset(mode,0,sizeof(mode));
for(i=0;i<n;i++)
{
scanf("%s",mail[i]);
for(j=0;j<n;j++)
{
if(mail[i][j]==‘.‘)
mail[i][j]=‘ ‘;
}
}
for(i=0;i<n;i++)
scanf("%s",mode[i]);
take();
map<string,int>mp;
mp.clear();
scanf("%d",&m);
for(i=0;i<m;i++)
{
scanf("%s",c);
mp[c]=1;
}
sort(E,E+4,cmp);
flag=-1;
for(i=0;i<4;i++)
{
memset(c,0,sizeof(c));
l=0;
for(j=0;j<H[i];j++)
{
if(E[i].s[j]==‘ ‘)
{
if(!mp[c])break;
memset(c,0,sizeof(c));
l=0;
}
else if(j==H[i]-1)
{
c[l++]=E[i].s[j];
if(!mp[c])break;
flag=i;
}
else if(E[i].s[j]!=‘ ‘)
{
c[l++]=E[i].s[j];
}
}
if(flag!=-1)break;
}
printf("Case #%d: ",t);
if(flag==-1)
printf("FAIL TO DECRYPT\n");
else
printf("%s\n",E[flag].s);
}
return 0;
}
hdu 4119 Isabella's Message【字符串模拟】