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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
const int maxn=2e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t,cnt[],ok,pos;
string a;
char ans[][];
int main()
{
int i,j;
ans[][]=ans[][]=;
memset(cnt,-,sizeof(cnt));
cin>>a;
for(i=;a[i];i++)
{
if(cnt[a[i]]!=-)ok=i-cnt[a[i]]-,pos=cnt[a[i]];
else cnt[a[i]]=i;
}
if(!ok)return *puts("Impossible");
int cnt;
ans[][-ok/]=a[pos];
for(i=-ok/,cnt=;i<;i++,cnt++)ans[][i]=a[pos+cnt];
for(i=;i>=-ok/;i--,cnt++)ans[][i]=a[pos+cnt];
if(ok&)ans[][i]=a[pos+cnt],cnt+=,i--;else cnt++;
for(;i>=;i--,cnt++)ans[][i]=a[pos+cnt>?pos+cnt-:pos+cnt];
for(i=;i<-ok/;cnt++,i++)ans[][i]=a[pos+cnt>?pos+cnt-:pos+cnt];
rep(i,,)printf("%s\n",ans[i]);
//system("Pause");
return ;
}

Hidden Word的更多相关文章

  1. Canada Cup 2016 C. Hidden Word

    C. Hidden Word time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  2. Canada Cup 2016 C. Hidden Word 构造模拟题

    http://codeforces.com/contest/725/problem/C Each English letter occurs at least once in s. 注意到题目有这样一 ...

  3. 【36.11%】【codeforces 725C】Hidden Word

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. Codeforces Canada Cup 2016

    A. Jumping Ball time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  5. codeforces 725/C

    Hidden Word time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  6. dmalloc 原文 翻译整理

    http://blog.csdn.net/cardinal_508/article/details/5553387 L13 从快速入门开始(Quickstart) 这个库是一个文件中所有简化用法中最常 ...

  7. c malloc分配内存

    php中的内存分配有用类似emalloc这样的函数,emalloc实际上是C语言中的malloc的一层封装,php启动后,会向OS申请一块内存,可以理解为内存池,以后的php分配内存都是在这块内存池中 ...

  8. malloc.c

    glibc-2.14中的malloc.c源代码,供研究malloc和free实现使用: /* Malloc implementation for multiple threads without lo ...

  9. 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    先把代码扔上来 E. Field of Wonders time limit per test 3 seconds memory limit per test 256 megabytes input ...

随机推荐

  1. C# 读书笔记之类与结构体

    类和结构体都包括数据和操作数据的方法 类的定义形式 class PhoneCustomer{public const string DayOfSendingBill = "Monday&qu ...

  2. 使用EasyBCD 从硬盘安装 deepin2014.1

    EasyBCD config  code: title Install Deepin2014 root (hd0,1) kernel (hd0,1)/vmlinuz boot=casper iso-s ...

  3. 7、js使用正则表达式验证

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. fatal error RC1004: unexpected end of file found处理方法

    资源编译器错误 RC1004 错误消息 遇到意外的文件结束 此错误是由于文本文件的最后一行中缺少换行符和回车符而造成的.

  5. debian root 可以远程登陆

    vim /etc/ssh/sshd_config FROM: PermitRootLogin without-password TO: PermitRootLogin yes

  6. xampp 搭建 web mac上

    1.安装 2.修改数据库密码,删除phpmyadmin  ,用navicat 控制数据库 3.修改/Applications/XAMPP/xamppfiles/etc/extra/httpd-vhos ...

  7. AFNetworking 关于JSON text did not start with array or object and option to allow fragments not set 错误

    AFHTTPSessionManager *manager =[AFHTTPSessionManager manager]; [manager GET:@"http://www.baidu. ...

  8. SELinux Policy Macros

    参考:http://selinuxproject.org/page/NB_RefPolicy Directory Macros macro expansion getattr_dir_perms ge ...

  9. 将dom4j格式化为标准的xml字符串

    StringWriter writer = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); fo ...

  10. SuperMapPy 批量拼接 GeoTiff影像

    影像拼接工具使用说明 一.影像像素位深检查 1.采用开源库GDAL的gdalinfo.exe读取GeoTiff文件的信息,如类型.投影,范围等. 2.采用DOS脚本遍历所有GeoTiff文件,输出各个 ...