
http://codeforces.com/contest/725/problem/C
Each English letter occurs at least once in s.
注意到题目有这样一句话,那么就是说S中只有一个重复的字母。一定要看到这句话,不然做不了。
然后就找到pos1和pos2分别代表那两个字母的位置,把他们中间的所有字母对折一下,放在最右边就可以了。因为这样才能用上同一个位置。
只有连续两个相同的字母才会impossible,同样是因为只有两个相同的字母。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = + ;
char str[];
int book[maxn];
char ans[maxn][maxn];
void work() {
// for (int i = 1; i <= 2; ++i) {
// for (int j = 1; j <= 13; ++j) {
// ans[i][j] = 'a';
// }
// }
scanf("%s", str + );
for (int i = ; i <= ; ++i) {
book[str[i]]++;
}
int pos[];
int cur = ;
for (int i = ; i <= ; ++i) {
if (book[str[i]] == ) pos[cur++] = i;
}
if (pos[] == pos[] - ) {
cout << "Impossible" << endl;
return;
}
// cout << pos[1] << " " << pos[2] << endl;
int ff = pos[];
int len = pos[] - pos[] - ;
int t = len / ;
ans[][ - t] = str[pos[]];
for (int i = - t + ; i <= ; ++i) {
ans[][i] = str[++ff];
}
int flag = (len % ) == ;
for (int i = ; i >= - t + flag; --i) {
ans[][i] = str[++ff];
} int to = - t - ;
cur = ;
if (to <= ) {
cur = ;
to = ;
}
for (int i = pos[] + ; i <= ; ++i) {
ans[cur][to] = str[i];
if (cur == ) to++;
else to--;
if (to <= ) {
to = ;
cur = ;
}
}
for (int i = ; i <= pos[] - ; ++i) {
ans[cur][to] = str[i];
if (cur == ) to++;
else --to;
if (to <= ) {
to = ;
cur = ;
}
}
for (int i = ; i <= ; ++i) {
for (int j = ; j <= ; ++j) {
cout << ans[i][j];
}
cout << endl;
}
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
work();
return ;
}