博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Hidden Word
阅读量:4931 次
发布时间:2019-06-11

本文共 3611 字,大约阅读时间需要 12 分钟。

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 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define rep(i,m,n) for(i=m;i<=n;i++)#define rsp(it,s) for(set
::iterator it=s.begin();it!=s.end();it++)#define mod 1000000007#define inf 0x3f3f3f3f#define vi vector
#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
#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\n",ans[i]); //system("Pause"); return 0;}

转载于:https://www.cnblogs.com/dyzll/p/6002472.html

你可能感兴趣的文章
[转]一些好的原则
查看>>
【分享】写代码如坐禅:你是哪一类程序员?
查看>>
【图文教程】CentOS 7配置静态IP地址
查看>>
数据访问层的几种数据库连接方式
查看>>
session原理及实现集群session的方案原理
查看>>
Linux命令之sed
查看>>
超级gnFindWindow
查看>>
[2012山东ACM省赛] Pick apples (贪心,完全背包,枚举)
查看>>
Android 中的Canvas画图
查看>>
2017.2.6
查看>>
WebApplicationInitializer究 Spring 3.1之无web.xml式 基于代码配置的servlet3.0应用
查看>>
C# /VB.NET 创建PDF项目符号列表和多级编号列表
查看>>
数位dp-入门模板题 hdu2089
查看>>
DP---Mahjong tree
查看>>
二叉树遍历
查看>>
求第N数大问题
查看>>
Python-str-操作-6
查看>>
用jQuery Mobile做HTML5移动应用的三个优缺点
查看>>
求两个长度相等的排序数组的上中位数
查看>>
推荐搜索引擎及搜索技巧
查看>>