trainging contest#2(2011成都现场赛)I BY Hyoga

模拟题,用STL可以快速A掉。

我傻×的读错题目了,耗了好长时间……注意题目这句话:The way to compare two messages is to compare the words of two messages one by one, and the first pair of different words in the two messages will determine the lexicographic order of them. 

字典序大小的比较方式是一个一个单词的比!

#include<cstdio>
#include<string>
#include<cstring>
#include<set>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn=112;
set<string>myset;
vector<string>ans[maxn];
int d[maxn][maxn],tt[maxn][maxn];
char a[maxn][maxn];
char rtmp[maxn];
int n;
void cpy(int x[][maxn],int b[][maxn])
{
    for(int i=1;i<=n;i++)
     for(int j=1;j<=n;j++)
     x[i][j]=b[i][j];
}
void rotate(int x[][maxn])
{
    for(int i=1;i<=n;i++)
     for(int j=1;j<=n;j++)
    tt[j][n-i+1]=x[i][j];
    cpy(x,tt);
}
int main()
{
    int sec;
    scanf("%d",&sec);
    for(int z=1;z<=sec;z++)
    {
        int tot=0;
        myset.clear();
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%s",rtmp);
            for(int j=1;j<=n;j++)
            a[i][j]=rtmp[j-1];
        }

        for(int i=1;i<=n;i++)
        {
            scanf("%s",rtmp);
            for(int j=1;j<=n;j++)
            if(rtmp[j-1]=='*')d[i][j]=1;//dong
            else d[i][j]=0;
        }
        int m;
        scanf("%d",&m);
        for(int i=1;i<=m;i++)
        {
            string s;
            cin>>s;
            myset.insert(s);
        }

        int tmp[maxn][maxn];
        cpy(tmp,d);
        for(int w=1;w<=4;w++)
        {
            cpy(d,tmp);

            string t;t.clear();
            for(int q=1;q<=4;q++)
            {
                for(int i=1;i<=n;i++)
                 for(int j=1;j<=n;j++)
                if(d[i][j]==1) t.push_back(a[i][j]);
                rotate(d);
            }

            int l=t.length();
            bool flag=true;
            string s;s.clear();
            tot++;ans[tot].clear();

            for(int i=0;i<l;i++)
            {
                if(t[i]!='.')s.push_back(t[i]);
                if((t[i]=='.'||i==l-1)&&s.length()>0)
                {
                    if(myset.count(s)<=0){flag=false;break;}
                    else ans[tot].push_back(s);

                    s.clear();
                }
            }

            if(!flag)
                tot--;
            rotate(tmp);
        }


        printf("Case #%d: ",z);
        if(tot==0)cout<<"FAIL TO DECRYPT\n";
        else
        {
            int k=1;
            for(int i=2;i<=tot;i++)
            {
                for(int j=0;j<ans[i].size();j++)
                if(ans[i][j]<ans[k][j]){k=i;break;}
                else if(ans[i][j]>ans[k][j])break;
            }

            //
            for(int i=0;i<ans[k].size();i++)
            if(i+1!=ans[k].size())cout<<ans[k][i]<<" ";
            else cout<<ans[k][i]<<"\n";
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值