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. webpack配置vue项目

    npm init 安装webpack,webpack-cli 新建src目录,在src目录下新建main.js

  2. 【Leetcode链表】反转链表 II(92)

    题目 反转从位置 m 到 n 的链表.请使用一趟扫描完成反转. 说明: 1 ≤ m ≤ n ≤ 链表长度. 示例: 输入: 1->2->3->4->5->NULL, m ...

  3. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第六章:在Direct3D中绘制

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第六章:在Direct3D中绘制 代码工程地址: https://gi ...

  4. UDP传输对象--JavaSE考试题

    Server.java package com.sxt.udp.object; import java.io.ByteArrayInputStream; import java.io.ObjectIn ...

  5. Kafka 简易教程

    1.初识概念 Apache Kafka是一个分布式消息发布订阅系统. TopicKafka将消息种子(Feed)分门别类, 每一类的消息称之为话题(Topic). Producer发布消息的对象称之为 ...

  6. HDU 5672 String【尺取法】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5672 题意: 有一个10≤长度≤1,000,000的字符串,仅由小写字母构成.求有多少个子串,包含有 ...

  7. form表单提交,后台怎么获取select的值?后台直接获取即可,和input方式一样。

    form表单提交,后台怎么获取select的值? 后台直接获取即可,和后台获取input的值方式一样. form提交后,后台直接根据select的name获取即可,即getPara("XXX ...

  8. @loj - 2865@ 「IOI2018」狼人

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 在日本的茨城县内共有 N 个城市和 M 条道路.这些城市是根据人 ...

  9. 12 将类处理为excel,再将excel处理为类(界限计划3)

    中间使用map作为中间处理 将类处理为excel: 1.读取类转为map //读取btl,转为map public static Map getBtlMap(String rule, BTLDAO b ...

  10. 怎么清除火狐浏览器的cookie?

    火狐浏览器清除Cookie方法/步骤 1.打开火狐浏览器.并在火狐浏览器工具栏找到并单击“工具”下的“选项”. 2.在打开的“火狐浏览器选项”程序窗口中,找到工具栏中的“隐私”并单击,在隐私选项下找到 ...