C. 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

思路:先将初始字符串t删去重复的字母,然后按初始的顺序枚举可能的字符组合(26种),将其分成两行,判断是否符合条件即可。
总结:这是一道思维题,简单搜索的部分,也是对编码功底的锻炼。写了(改了)好久,好久。。
代码:
 #include "cstdio"
#include "algorithm"
#include "cstring"
#include "queue"
#include "cmath"
#include "vector"
#include "map"
#include "stdlib.h"
#include "set"
typedef long long ll;
using namespace std;
const int N=1e4+;
const int mod=1e9+;
#define db double
//int a[N];
//set<int> q;
//map<int ,int > u;
//ll dp[N];
char t[];
char f[];
int m=,pd;
int a[],b[];
char s[][],g[];
int d[][]={{,},{,-},{,},{-,},{-,-},{-,},{,},{,-}};//刚开始没带等号
void dfs(int x,int y,int m){
if(m==) pd=;//m写成26了,最后的错误
a[s[x][y]-'A']--;
for(int i=;i<;i++){
int nx=x+d[i][],ny=y+d[i][];
if(nx>=&&nx<&&ny>=&&ny<&&s[nx][ny]==g[m]&&a[s[nx][ny]-'A']>) {
dfs(nx, ny, m + );
}
}
}
int main()
{
scanf("%s",t);
strcpy(g,t);
char e,v;
for(int i=;i<;i++){
if(t[i]==t[i+]) {puts("Impossible");return ;}
v=t[i];
a[v-'A']++;//'A'写成'a'一直没查出来
if(a[v-'A']==) {
e=v;
for(int j=i+;j<;j++)
a[t[j]-'A']++;
for(int j=i+;j<;){
t[i++]=t[j++];
}
}
}
for(int i=;i<;i++){
b[i]=a[i];
t[i+]=t[i];
}
for(int i=;i<;i++){
int p=;
for(int j=i;j<+i;){
f[p++]=t[j++];
}
int k=;
for(int l=;l<;l++) s[][l]=f[l];//开始数组开13,开小了
for(int l=;l>=;l--) s[][l]=f[k++];
pd=;
for(int ii=;ii<;ii++){
for(int j=;j<;j++){
if(s[ii][j]==t[]){
dfs(ii,j,);
if(pd) {
for(int kk=;kk<;kk++)
puts(s[kk]);
return ;
}
}
}
}
memcpy(a,b, sizeof(a));
}
return ;
}

最新文章

  1. ORB
  2. Mongdb使用客户端
  3. web项目首页提示404
  4. hdoj 1045 Fire Net
  5. Qt Creator error: LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
  6. 模拟红外协议C程序——接收模块
  7. jquery.validate提示错误方法
  8. nopCommerce 3.9 大波浪系列 之 可退款的支付宝插件(下)
  9. InnoDB online DDL与快速索引创建
  10. 【Unity Shaders】Reflecting Your World —— Unity3D中简单的Cubemap反射
  11. 【数学建模】MATLAB语法
  12. idea构建spark开发环境,并本地运行wordcount
  13. 【LeetCode每天一题】Rotate Image(旋转矩阵)
  14. ORA-01078和LRM-00109问题导致ORACLE启动失败解决方法
  15. sys系统用户长时间未登录导致密码过期
  16. 关于部署传统的Dynamic Web项目
  17. Selenium2(WebDriver)总结(一)---启动浏览器、设置profile&amp;加载插件
  18. [转]Python多线程与多线程中join()的用法
  19. Caffe cpu版本 Linux配置命令及搭建
  20. windows调试本地启动的tomcat

热门文章

  1. Angular - - form.FormController、ngModel.NgModelController
  2. 【bzoj3998】 TJOI2015—弦论
  3. 在向服务器发送请求时发生传输级错误。 (provider: TCP 提供程序, error: 0 - 远程主机强迫关闭了一个现有的连接。)
  4. Java jsp 示例
  5. db2 数据类型
  6. thinkphp 配置项总结
  7. C# WInform 界面左导航菜单
  8. 抽象类 abstract 和 接口 interface 类的区别
  9. Redis 介绍与安装
  10. 华为oj---合并数组