1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-23 21:58:41 +00:00
202401-programming-assignments/【实践课外】9.数组3/7-6 数组-动车上.c

34 lines
666 B
C
Raw Normal View History

2024-11-15 09:07:17 +00:00
#include <stdio.h>
#include <string.h>
int k;
char s[105];
int main() {
scanf("%d\n%s", &k, s);
int len = strlen(s);
for (int i = 0, cnt = 0; i < len; i += k, cnt++) {
if (i + k - 1 < len) {
if (cnt % 2 == 1) {
for (int j = i + k - 1; j >= i; j--) {
printf("%c", s[j]);
}
} else {
for (int j = i; j < i + k; j++) {
printf("%c", s[j]);
}
}
} else {
for (int j = i; j < len; j++) {
printf("%c", s[j]);
}
}
}
printf("\n");
return 0;
}