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+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t,cnt[],ok,pos;
string a;
char ans[][];
int main()
{
int i,j;
ans[][]=ans[][]=;
memset(cnt,-,sizeof(cnt));
cin>>a;
for(i=;a[i];i++)
{
if(cnt[a[i]]!=-)ok=i-cnt[a[i]]-,pos=cnt[a[i]];
else cnt[a[i]]=i;
}
if(!ok)return *puts("Impossible");
int cnt;
ans[][-ok/]=a[pos];
for(i=-ok/,cnt=;i<;i++,cnt++)ans[][i]=a[pos+cnt];
for(i=;i>=-ok/;i--,cnt++)ans[][i]=a[pos+cnt];
if(ok&)ans[][i]=a[pos+cnt],cnt+=,i--;else cnt++;
for(;i>=;i--,cnt++)ans[][i]=a[pos+cnt>?pos+cnt-:pos+cnt];
for(i=;i<-ok/;cnt++,i++)ans[][i]=a[pos+cnt>?pos+cnt-:pos+cnt];
rep(i,,)printf("%s\n",ans[i]);
//system("Pause");
return ;
}

最新文章

  1. 激!GSS系列
  2. App Store
  3. hdu 4622 **
  4. 【BZOJ】1468: Tree(点分治)
  5. MYSQL C API : mysql_real_connect()
  6. java_web用户的自动登录模块的实现
  7. telnet配置和telnet用法
  8. phpmailer发送邮件服务
  9. JQuery 数组获取和删除元素
  10. cf1136E. Nastya Hasn&#39;t Written a Legend(二分 线段树)
  11. ASP.NET MVC 4 (八) URL链接和Ajax帮助函数
  12. Python学习URL
  13. contenteditable设置元素可编辑
  14. d3dx9库函数
  15. ABBYY FineReader操作技巧
  16. jzoj5806
  17. 用Html5与Asp.net MVC上传多个文件
  18. [转]OrCAD PSpice DIODE model parameter
  19. falsk注册etcd
  20. Python笔试面试题_牛客(待完善)

热门文章

  1. KindeEditor图片上传插件用法
  2. 使用Angular构建单页面应用(SPA)
  3. Excel教程(4) - 数据库函数
  4. 28.按要求编写一个Java应用程序: (1)定义一个类,描述一个矩形,包含有长、宽两种属性,和计算面积方法。 (2)编写一个类,继承自矩形类,同时该类描述长方体,具有长、宽、高属性, 和计算体积的方法。 (3)编写一个测试类,对以上两个类进行测试,创建一个长方体,定义其长、 宽、高,输出其底面积和体积。
  5. manifest中的largeHeap是干什么用的?
  6. php根据IP获取IP所在城市
  7. iOS导航栏主题
  8. 让上下两个DIV块之间有一定距离或没有距离
  9. memcached + php 扩展 for ubuntu
  10. Android中截取当前屏幕图片