time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard 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

【题解】



构造题;

这道题的输入会保证每个字母最多出现两次.

因为输入说每个字母至少出现一次,一共有26个字母,输入27个字符。则只有一个重复的,其他都只出现一次;



如上图所示的方法构造;

上面两个正方形是输入里面相同的字符所在的位置;

之后再把两边填充一下就好;

输入如果有两个连续的相同字符则不能构造出上图所述情况;

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#define LL long long using namespace std; int s3[3][30+300] = { 0 };
string s1;
int cnt[30+300]; int main()
{
//freopen("F:\\rush.txt", "r", stdin);
int dis,pos,yuan;
cin >> s1;
int len = s1.size();
string s2 = " ";
s2 += s1;
s1 = s2;
for (int i = 1; i <= len; i++)
{
int t = s1[i] - 'A' + 1;
if (!cnt[t])
cnt[t] = i;
else
{
if (cnt[t] == i - 1)//连续的则不可能
{
puts("Impossible");
return 0;
}
dis = i - cnt[t] + 1;//记录前一个和当前所在的位置的差
pos = cnt[t];//从前一个位置的开始构造
yuan = i;
break;
}
}
int st = (13 - dis/2)+1,now=2;//st是第二行的开始位置
s3[2][st] = s1[pos]-'A'+1;//now=2表示在搞第二行
st++, pos++;
int fx = 1;//这是第二行从左往右
while (s1[pos] != s1[yuan])
{
if (st > 13)//开始搞第二行
{
st = 13;
fx = -1;//第二行是从右往左
now = 1;//now是当前的行数
}
s3[now][st] = s1[pos]-'A'+1;//赋值
pos++;//搞下一个
st +=fx;
}
if (s1[1] != s1[27])//最后一个字符和第一个相同则不需要填充两边了
{
pos++;
if (pos > 27)//要按照第一行的最右到最左然后从第二行的最左到最右,这样就算又变成第一个,也能继续处理,且答案也是正确的;
pos = 1;
s3[now][st] = s1[pos] - 'A' + 1;
pos++;
if (pos > 27)
pos = 1;
st--;
while (s1[pos] != s1[yuan])
{
if (st < 1)//小于1表示要到第二行了;
{
st = 1;
fx = 1;//方向变成从左到右了;
now = 2;//第二行继续搞;
}
int t = s1[pos] - 'A' + 1;
s3[now][st] = t;
pos++;
if (pos > 27)
pos = 1;
st += fx;
}
}
for (int i = 1; i <= 13; i++)
putchar(char(s3[1][i] + 'A' - 1));
puts("");
for (int i = 1;i <= 13;i++)
putchar(char(s3[2][i] + 'A' - 1));
puts("");
return 0;
}

最新文章

  1. 如何学习JavaScript
  2. (Hibernate进阶)Hibernate映射——一对一单向关联映射(五)
  3. dblink
  4. python学习笔记六 面向对象相关下(基础篇)
  5. [moka同学笔记]yii2.0导航栏
  6. Android Studio利用Gradle删除没有使用到的资源和代码文件
  7. Ubuntu 14.04 AM335x TI-RTOS 编译
  8. php字符串与正则表达式试题 Zend权威认证试题讲解
  9. linux内核驱动模型
  10. C语言的本质(7)——C语言运算符大全
  11. 【Java基础】“数三退一”问题的代码实现
  12. git使用系列(一)
  13. html倒计时代码
  14. CMDB资产管理系统开发【day26】:数据正式存入待存区
  15. ORM创建多表以及多表的增删改查
  16. 基于CC2530/CC2430 的温度采集系统--DS18B20
  17. python之MRO和C3算法
  18. js 停止事件冒泡 阻止浏览器的默认行为(比如阻止超连接 # )
  19. js实现照片墙效果
  20. Sqoop-1.4.6安装部署及详细使用介绍

热门文章

  1. 如何在Liferay 7中创建一个简单的JSF Portlet
  2. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十一章:模板测试
  3. 使用pstack和gdb调试死锁
  4. SDUT-2117_数据结构实验之链表二:逆序建立链表
  5. HSV 和 HLS颜色空间
  6. 解决移动端1px边框问题的几种方法
  7. PHP 7.0新增特性详解
  8. 1878: [SDOI2009]HH的项 莫队算法-离线查询区间内部不同数字的个数
  9. oracle函数 power(x,y)
  10. 如何利用aop的环绕消息处理log, 以及各种坑的记录