• Hidden Word


    Hidden Word
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Let’s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of a grid:

    ABCDEFGHIJKLM
    NOPQRSTUVWXYZ

    We say that two tiles are adjacent if they share a side or a corner. In the example grid above, the tile with the letter 'A' is adjacent only to the tiles with letters 'B', 'N', and 'O'. A tile is not adjacent to itself.

    A sequence of tiles is called a path if each tile in the sequence is adjacent to the tile which follows it (except for the last tile in the sequence, which of course has no successor). In this example, "ABC" is a path, and so is "KXWIHIJK". "MAB" is not a path because 'M' is not adjacent to 'A'. A single tile can be used more than once by a path (though the tile cannot occupy two consecutive places in the path because no tile is adjacent to itself).

    You’re given a string s which consists of 27 upper-case English letters. Each English letter occurs at least once in s. Find a grid that contains a path whose tiles, viewed in the order that the path visits them, form the string s. If there’s no solution, print "Impossible" (without the quotes).

    Input

    The only line of the input contains the string s, consisting of 27 upper-case English letters. Each English letter occurs at least once in s.

    Output

    Output two lines, each consisting of 13 upper-case English characters, representing the rows of the grid. If there are multiple solutions, print any of them. If there is no solution print "Impossible".

    Examples
    input
    ABCDEFGHIJKLMNOPQRSGTUVWXYZ
    output
    YXWVUTGHIJKLM
    ZABCDEFSRQPON
    input
    BUVTYZFQSNRIWOXXGJLKACPEMDH
    output
    Impossible
    分析:注意观察除了相邻的两个字符以外,其他都可以,模拟即可;
    代码:
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <cstring>
    #include <string>
    #include <set>
    #include <map>
    #include <unordered_map>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <list>
    #define rep(i,m,n) for(i=m;i<=n;i++)
    #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
    #define mod 1000000007
    #define inf 0x3f3f3f3f
    #define vi vector<int>
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define ll long long
    #define pi acos(-1.0)
    #define pii pair<int,int>
    #define Lson L, mid, ls[rt]
    #define Rson mid+1, R, rs[rt]
    #define sys system("pause")
    const int maxn=2e5+10;
    using namespace std;
    ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
    ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
    inline ll read()
    {
        ll x=0;int f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int n,m,k,t,cnt[300],ok,pos;
    string a;
    char ans[2][14];
    int main()
    {
        int i,j;
        ans[0][13]=ans[1][13]=0;
        memset(cnt,-1,sizeof(cnt));
        cin>>a;
        for(i=0;a[i];i++)
        {
            if(cnt[a[i]]!=-1)ok=i-cnt[a[i]]-1,pos=cnt[a[i]];
            else cnt[a[i]]=i;
        }
        if(!ok)return 0*puts("Impossible");
        int cnt;
        ans[0][12-ok/2]=a[pos];
        for(i=13-ok/2,cnt=1;i<13;i++,cnt++)ans[0][i]=a[pos+cnt];
        for(i=12;i>=13-ok/2;i--,cnt++)ans[1][i]=a[pos+cnt];
        if(ok&1)ans[1][i]=a[pos+cnt],cnt+=2,i--;else cnt++;
        for(;i>=0;i--,cnt++)ans[1][i]=a[pos+cnt>26?pos+cnt-27:pos+cnt];
        for(i=0;i<12-ok/2;cnt++,i++)ans[0][i]=a[pos+cnt>26?pos+cnt-27:pos+cnt];
        rep(i,0,1)printf("%s
    ",ans[i]);
        //system("Pause");
        return 0;
    }
  • 相关阅读:
    javascript得知
    一旦配置oracle em经验
    windows 下一个mysql password忘记改变
    彩色图像--图像切 色彩空间切割
    Delphi 6 Web Services初步评估之三(转)
    Delphi 用Web App Debugger简单调试ISAPI 转
    Delphi socket() 函数的应用
    用Delphi实现WinSocket高级应用
    delphi编写winsocket的流程
    Delphi使用NativeXml访问XML文件
  • 原文地址:https://www.cnblogs.com/dyzll/p/6002472.html
Copyright © 2020-2023  润新知