a1031题解

对于输入输出 以及字符下标的对应 一定要注意!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

#include<cstring>
int () {
char S[100];
scanf("%s", S);
int n1, n2, n3;
int N = strlen(S);
int max = 0;
for(int i = 3; i <= N; i++) {
n2 = i;
for(int j = 0; j <= n2; j++) {
n1 = j;
n3 = j;
if(n1 + n2 + n3 - 2 == N){
if(j > max) {
max = j;
}
}

}
}
n1 = max;
n2 = N + 2 - n1 * 2;
n3 = max;

//printf("%d %d %dn", n1, n2, n3);
for(int i = 0; i < max - 1; i++) {
printf("%c", S[i]);
for(int j = 0; j < n2 - 2; j++) {
printf(" ");
}
printf("%cn", S[N - i - 1]);
}
for(int i = n1 - 1; i <= n1 + n2 - 2; i++) {
printf("%c", S[i]);
}
return 0;
}