问题链接:UVA11192 Group Reverse。入门练习题,用C语言编写程序。
AC的C语言程序如下:
/* UVA11192 Group Reverse */ #include <stdio.h> #include <string.h> #define MAXN 100 int main(void) { int n, start, end, i; char s[MAXN], c; while(scanf("%d", &n) != EOF && n != 0) { scanf("%s", s); n = strlen(s) / n; for(i=0; s[i]; i+=n) { start = i; end = i + n - 1; while(start < end) { c = s[start]; s[start] = s[end]; s[end] = c; start++; end--; } } printf("%s\n", s); } return 0; }
时间: 2024-10-18 01:20:23