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;
}

【36.11%】【codeforces 725C】Hidden Word的更多相关文章

  1. JAVA 基础编程练习题11 【程序 11 求不重复数字】

    11 [程序 11 求不重复数字] 题目:有 1.2.3.4 个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 程序分析:可填在百位.十位.个位的数字都是 1.2.3.4.组成所有的排列后 ...

  2. 【2020.11.28提高组模拟】T1染色(color)

    [2020.11.28提高组模拟]T1染色(color) 题目 题目描述 给定 \(n\),你现在需要给整数 \(1\) 到 \(n\) 进行染色,使得对于所有的 \(1\leq i<j\leq ...

  3. Cmake新手使用日记(1)【C++11下的初体验】

    第一次使用Cmake,搜索了很多使用教程,包括<Cmake实践>.<Cmake手册>等,但是在针对最新的C++11条件下编程还是会存在一点点问题,需要实验很多次错误并搜索大量文 ...

  4. Java面向对象笔记 • 【第11章 Swing高级应用】

    全部章节   >>>> 本章目录 11.1 JTable表格组件 11.1.1 JTable表格组件 11.1.2 实践练习 11.2 菜单组件 11.2.1 菜单组件 11. ...

  5. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  6. 【2020.11.30提高组模拟】剪辣椒(chilli)

    剪辣椒(chilli) 题目描述 在花园里劳累了一上午之后,你决定用自己种的干辣椒奖励自己. 你有n个辣椒,这些辣椒用n-1条绳子连接在一起,任意两个辣椒通过用若干个绳子相连,即形成一棵树. 你决定分 ...

  7. 【2020.11.30提高组模拟】删边(delete)

    删边(delete) 题目 题目描述 给你一棵n个结点的树,每个结点有一个权值,删除一条边的费用为该边连接的两个子树中结点权值最大值之和.现要删除树中的所有边,删除边的顺序可以任意设定,请计算出所有方 ...

  8. 【2020.11.28提高组模拟】T2 序列(array)

    序列(array) 题目描述 ​给定一个长为 \(m\) 的序列 \(a\). 有一个长为 \(m\) 的序列 \(b\),需满足 \(0\leq b_i \leq n\),\(\sum_{i=1}^ ...

  9. 【36.86%】【codeforces 558B】Amr and The Large Array

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. 使用virtualenv使得Python2和Python3并存

    1:下载python3源码并安装 wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz .tgz cd Python-.tgz . ...

  2. 比较全面的一个PHP缓存类解析

    转自:http://www.blhere.com/1164.html 一.引论 PHP,一门最近几年兴起的web设计脚本语言,由于它的强大和可伸缩性,近几年来得到长足的发展,php相比传统的asp网站 ...

  3. 【Leetcode链表】移除链表元素(203)

    题目 删除链表中等于给定值 val 的所有节点. 示例: 输入: 1->2->6->3->4->5->6, val = 6 输出: 1->2->3-&g ...

  4. SpringMVC的简单传值总结

    之前学习SpringMVC时感觉他的传值很神奇:简便,快捷,高效. 今天写几个简单的传值与大家分享,希望能对大家有帮助. 一. 从后往前传: (1) @Controller @RequestMappi ...

  5. 从零学React Native之09可触摸组件

    可触摸组件有: TouchableHighlight,TouchableNativeFeedback,TouchableOpacity,TouchableWithoutFeedback 1. Touc ...

  6. 关于使用 Java 分片读\写文件

    分片读取文件方法: /** * 分片读取文件块 * * @param path 文件路径 * @param position 角标 * @param blockSize 文件块大小 * @return ...

  7. python 字典元素删减

  8. python 字符串(str)

  9. qt 自定义窗口显示鼠标划过的轨迹

    鼠标事件分为四种: 1.按下 2.抬起 3.移动 4.双击 鼠标事件继承与QWidget void mouseDoubleClickEvent(QMouseEvent *event) void mou ...

  10. python 处理图像出现The lower bounary is neither an array of the same size and same type as src, nor a scalar in function inRange

    在用python处理图像过程中出现如下错误 导致这个错误的原因是im是二维,而lower_green和upper_green是三维,所以无法用inRange处理. 由上图可以看出image本来是具有高 ...