-
Notifications
You must be signed in to change notification settings - Fork 0
/
To and Fro.c
51 lines (49 loc) · 1.04 KB
/
To and Fro.c
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
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// main.c
// To and Fro
//
// Created by 国与同 on 16/5/13.
// Copyright © 2016年 国与同. All rights reserved.
//
#include <stdio.h>
#include <string.h>
int main() {
int m;
scanf("%d",&m);
char a[300];
int b,c;
int i,j;
int count;
char z;
int x,y;
while (m != 0) {
scanf("%s",a);
b = strlen(a);
c = b / m;
count = 0;
for(i = 0; i <= b - m; i = i + m){
if(count % 2 == 1){
x = i;
y = i + m - 1;
for(j = 1; j <= m /2; j++){
z = a[x];
a[x] = a[y];
a[y] = z;
x++;
y--;
}
}
count++;
}
for(i = 0; i < m ; i++){
count = i;
for(j = 0; j <= c; j++){
printf("%c",a[count]);
count = count + m;
}
}
printf("\n");
memset(a, '\0', sizeof(a));
scanf("%d",&m);
}
}