博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Hidden Word
阅读量:4933 次
发布时间:2019-06-11

本文共 3611 字,大约阅读时间需要 12 分钟。

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 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define rep(i,m,n) for(i=m;i<=n;i++)#define rsp(it,s) for(set
::iterator it=s.begin();it!=s.end();it++)#define mod 1000000007#define inf 0x3f3f3f3f#define vi vector
#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
#define Lson L, mid, ls[rt]#define Rson mid+1, R, rs[rt]#define sys system("pause")const int maxn=2e5+10;using namespace std;ll gcd(ll p,ll q){ return q==0?p:gcd(q,p%q);}ll qpow(ll p,ll q){ll f=1;while(q){ if(q&1)f=f*p;p=p*p;q>>=1;}return f;}inline ll read(){ ll x=0;int f=1;char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}int n,m,k,t,cnt[300],ok,pos;string a;char ans[2][14];int main(){ int i,j; ans[0][13]=ans[1][13]=0; memset(cnt,-1,sizeof(cnt)); cin>>a; for(i=0;a[i];i++) { if(cnt[a[i]]!=-1)ok=i-cnt[a[i]]-1,pos=cnt[a[i]]; else cnt[a[i]]=i; } if(!ok)return 0*puts("Impossible"); int cnt; ans[0][12-ok/2]=a[pos]; for(i=13-ok/2,cnt=1;i<13;i++,cnt++)ans[0][i]=a[pos+cnt]; for(i=12;i>=13-ok/2;i--,cnt++)ans[1][i]=a[pos+cnt]; if(ok&1)ans[1][i]=a[pos+cnt],cnt+=2,i--;else cnt++; for(;i>=0;i--,cnt++)ans[1][i]=a[pos+cnt>26?pos+cnt-27:pos+cnt]; for(i=0;i<12-ok/2;cnt++,i++)ans[0][i]=a[pos+cnt>26?pos+cnt-27:pos+cnt]; rep(i,0,1)printf("%s\n",ans[i]); //system("Pause"); return 0;}

转载于:https://www.cnblogs.com/dyzll/p/6002472.html

你可能感兴趣的文章
升级win10后无法使用桥接网络解决方法
查看>>
如何进行跨网段的远程唤醒
查看>>
数据挖掘-同比与环比
查看>>
nginx+php详解
查看>>
怎样取php一个字符串中的某个字符
查看>>
我的友情链接
查看>>
RedHat6 管理应用服务【11】
查看>>
stm32F10x复习-1
查看>>
redis的学习使用(ubuntu系统下)
查看>>
20135226黄坤信息安全系统设计基础期末总结
查看>>
轻松快捷创建VSFTP虚拟用户
查看>>
[转]Javascript原型继承
查看>>
[转] vue异步处理错误
查看>>
CSS 3D动画概述菜鸟级解读之一
查看>>
分布式系列文章 —— 从 ACID 到 CAP / BASE
查看>>
方法签名与方法重载
查看>>
cmake 变量
查看>>
[Programming Entity Framework] 第2章 探究实体数据模型(EDM)(一)
查看>>
shell环境
查看>>
Java调用C++类库--JNI
查看>>