Hidden Word

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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
【分析】先找到那个出现两次的字母的位置,然后分四种情况讨论,两次都在中间,一个在首一个在中间,一个在尾一个在中间,一个在首一个在尾。
两个位置之间的字母肯定是要分成两行的,然后就模拟了。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
typedef long long ll;
using namespace std;
const int N = ;
const int M = ;
int n=,m,k,l;
string str,s,a="",b="",c="",d="";
int vis[N];
int main() {
cin>>str;
vector<int>p;
for(int i=; i<str.size(); i++) {
vis[str[i]]++;
}
for(int i=; i<str.size(); i++) {
if(vis[str[i]]==) {
s[]=str[i];
p.push_back(i);
}
}//printf("%d %d\n",p[0],p[1]);
if(p.size()>||p[]-p[]==) {
puts("Impossible");
exit();
}
bool Find=false;
for(int i=; i<str.size(); i++) {
if(Find&&str[i]==s[])break;
if(!Find&&str[i]==s[])Find=true;
else if(Find)a+=str[i];
}
if(str[]!=s[]&&str[str.size()-]!=s[]) {
for(int i=a.size()/-; i>=; i--)b+=a[i];
for(int i=a.size()/; i<a.size(); i++)c+=a[i];
//cout<<b<<" "<<c<<endl;
for(k=p[];k>=&&b.size()<;k--)b+=str[k]; for(int i=str.size()-;b.size()<;i--)b+=str[i];
for(int i=p[]+;c.size()<&&i<str.size();i++)c+=str[i];
for(int i=;i<=k&&c.size()<;i++)c+=str[i];
cout<<b<<endl<<c<<endl;
} else if(str[]==s[]&&str[str.size()-]!=s[]){
for(int i=a.size()/-; i>=; i--)b+=a[i];
for(int i=a.size()/; i<a.size(); i++)c+=a[i];
for(k=p[];b.size()<;k++)b+=str[k];
for(int i=str.size()-;c.size()<;i--)c+=str[i];
cout<<b<<endl<<c<<endl;
} else if(str[]!=s[]&&str[str.size()-]==s[]){
for(int i=a.size()/-; i>=; i--)b+=a[i];
for(int i=a.size()/; i<a.size(); i++)c+=a[i];
for(k=p[];b.size()<;k--)b+=str[k];
for(int i=;c.size()<;i++)c+=str[i];
cout<<b<<endl<<c<<endl;
}else if(str[]==s[]&&str[str.size()-]==s[]){
for(int i=;i<;i++)b+=str[i];
for(int i=str.size()-;c.size()<;i--)c+=str[i];
cout<<b<<endl<<c<<endl;
}
return ;
}

codeforces 725/C的更多相关文章

  1. 【Codeforces Round 725】Canada Cup 2016

    模拟Canada Cup 2016,ABC三题,Rank1376 第三题卡住了 Codeforces 725 C 求出两个相同字符的位置,记为x和y. 然后考虑把相同的那个字符放在第一行的什么地方, ...

  2. 刷题记录:Codeforces Round #725 (Div. 3)

    Codeforces Round #725 (Div. 3) 20210704.网址:https://codeforces.com/contest/1538. 感觉这个比上一个要难. A 有一个n个数 ...

  3. Codeforces Round #725 (Div. 3) A-D,F题解

    A. Stone Game 思路:总共3种情况,都从最左端被拿走,都从最右端被拿走,左侧的从最左端被拿走且右侧的从最右端被拿走,取最小值即可 代码: //CF-725.A #include<bi ...

  4. Codeforces 725B Food on the Plane

    B. Food on the Plane time limit per test:2 seconds memory limit per test:256 megabytes input:standar ...

  5. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  8. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

随机推荐

  1. vim的编码设置

    VIM的相关字符编码主要有三个参数 fencs: 它是一个编码格式的猜测列表.当用vim打开某个文件时,会依次取这里面的编码进行解码,如果某个编码格式从头至尾解码正确,那么就用那个编码 fenc:它是 ...

  2. 详解x86、IA-32、IA-64等CPU系列

    x86架构起源于Intel公司在1978年推出的8086处理器.8086在1981年为IBM PC所选用,之后x86便成为了个人电脑的标准平台,成为历上最成功的CPU架构.8086是一款16位CPU, ...

  3. HTTPS Everywhere – 保障隐私和信息安全的利器

    HTTPS Everywhere 是一款 Chrome 扩展程序,对于支持 HTTPS 的网站默认打开 HTTPS 加密传输来保障信息安全(HTTPS 介绍). HTTPS Everywhere 受到 ...

  4. JavaScript:变量对象(Variable Object)

    引言:在使用JavaScript编程的时候,避免不了声明函数和变量,但是我们很少知道解释器是如何并且在什么地方找到这些函数和变量的,我们在引用这些对象的时候究竟发生了什么? 对ECMAScript程序 ...

  5. CSS引入方式的区别详解

    在web前端开发中,CSS是一种用来表现HTML或XML等文件样式的语言.很多处于web前端初学阶段的朋友,很多人都不知道CSS引入方式存在三种方法,css引入方式分别为标签内联书写.页面头部书写.外 ...

  6. Apparmor——Linux内核中的强制访问控制系统

      AppArmor 因为最近在研究OJ(oline judge)后台的安全模块的实现,所以一直在研究Linux下沙箱的东西,同时发现了Apparmor可以提供访问控制. AppArmor(Appli ...

  7. 转载 javascript中的正则表达式总结 一

    定义正则表达式的方法 定义正则表达式的方法有两种:构造函数定义和正则表达式直接量定义.例如: var reg1 = new RegExp('\d{5, 11}'); // 通过构造函数定义 var r ...

  8. js 微信分享

    一. //js接口 var shareme; var urls = window.location.href; if(isWeiXin()){   var weifileref=document.cr ...

  9. android中KSOAP2中的anytype{}问题

    如果web返回为空,即空字符串的时候,KSOAP2会返回一个anytype{}这样的一个串回来,要比对下是不是这个串,如果是就返回null,从而避免查不到数据时没有相应处理. if (jsonStr. ...

  10. 如何实现Magento产品批量导入?

    从事外贸的我们在工作中,经常需要添加成千上万个的产品,如果一个一个的去上传,要花费很多时间,有是很让人头痛,那么应该如何实现产品批量上传?如果使用的是Magento系统的话,那么你现在有福利了,因为M ...