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. TCPThree_C杯 Day1

    题解 或 正规题解 已经很详细,不再赘述. 跟着wjx打代码,不怕卡题. 忘开long long智障错误第四次左偏树

  2. Kernal Panic - Not syncing : VFS: unable to mount root fs on unknown-block

    升级了一下centos6.5 执行了 yum -y update reboot 出现了以下问题: Kernal Panic - Not syncing : VFS: unable to mount r ...

  3. X-editable 不能二次初始化的问题解决方案

    最近用到了 X-editable 可编辑表格插件,发现了一个头疼的问题,X-editable 不能对同一个 <a> 元素二次初始化. 如下代码举例:在页面加载完成时,用“数组1”填充一个下 ...

  4. LayUI+Echart实现图表

    1.首先 定义一个容器存放图表  需要指定这个容器的大小 <div class="layui-card"> <div class="layui-card ...

  5. 干货|Spring Cloud Bus 消息总线介绍

    继上一篇 干货|Spring Cloud Stream 体系及原理介绍 之后,本期我们来了解下 Spring Cloud 体系中的另外一个组件 Spring Cloud Bus (建议先熟悉 Spri ...

  6. 【Leetcode链表】回文链表(234)

    题目 请判断一个链表是否为回文链表. 示例 1: 输入: 1->2 输出: false 示例 2: 输入: 1->2->2->1 输出: true 进阶: 你能否用 O(n) ...

  7. C#面向对象基础 —— 类与对象

    文章来源: https://www.cnblogs.com/huluobozu/p/5070500.html 一.类与对象 类是面向对象编程的基本单元:类造出来的变量叫对象. 一个类包含俩种成员:字段 ...

  8. HDU-1114_Piggy-Bank

    Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem ...

  9. min-width:100%和max-width:100%的区别

    1.width:100%和width:auto width:100%,设定对象的宽度占父元素的100%不论设定元素的margin值是多少,不包含margin: width:auto,根据设定对象的实际 ...

  10. Jquery FormData文件异步上传 快速指南

    网站中文件的异步上传是个比较麻烦的问题,不过现在通过jquery 可以很容易的解决这个问题: 使用jquery2.1版本,较老版本不支持异步文件上传功能: 表单代码: <form id=&quo ...