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. Servlet FilterConfig

    FilterConfig的对象由Web容器创建.这个对象可用于获取web.xml文件中Filter的配置信息 文件:index.html <!DOCTYPE html> <html& ...

  2. Linux用户、群组和权限命令总结

    新建用户natasha,uid为1000,gid为555,备注信息为“master”   groupadd -g 555 natasha useradd -u 1000 -g 555 -c maste ...

  3. Java面向对象----多态概念,对象上下转型

    概念:同一操作作用于某一类对象,可以有不同的解释,产生不同的执行结果 多态存在的三个必要条件 需要存在继承和实现关系 同样的 方法调用而执行不同操作,运行不同的代码(重写操作) 在运行时父类或者接口的 ...

  4. 坚守安全第一准则!阿里云接连通过等保2.0测评、ISO国际认证

    斩获新资质 数字时代,数据的安全对于互联网用户来说显得尤为重要.阿里云更是一直坚持“安全第一准则”,致力于为客户的数据安全搭建更健全机制. 2019年5月,阿里云“电子政务云平台系统”正式通过网络安全 ...

  5. 浅析调用android的content provider(一)

            在Android下,查询联系人.通话记录等,需要用到content provider.但是,调用content provider时,Android框架内部是如何做的呢?这一系列文章就是 ...

  6. 9-1进程,进程池和socketserver

    一 进程: # 什么是进程 : 运行中的程序,计算机中最小的资源分配单位# 程序开始执行就会产生一个主进程# python中主进程里面启动一个进程 —— 子进程# 同时主进程也被称为父进程# 父子进程 ...

  7. SDUT-2134_数据结构实验之栈与队列四:括号匹配

    数据结构实验之栈与队列四:括号匹配 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 给你一串字符,不超过50个字符,可能 ...

  8. web移动开发小贴士

    1.判断手机类型 var u = navigator.userAgent; || u.indexOf(; //android var isiOS = !!u.match(/\(i[^;]+;( U;) ...

  9. 【[Offer收割]编程练习赛9 B】水陆距离

    [题目链接]:http://hihocoder.com/problemset/problem/1478 [题意] [题解] 一开始把所有的水域的位置都加入到队列中去; 然后跑一个bfs. 第一次到达的 ...

  10. day5_python之hashlib模块

    用来校验文本内容hash:一种算法 ,3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法三个特点:1.内容相同则h ...