forked from Ouditchya/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTOANDFRO.cpp
More file actions
51 lines (41 loc) · 780 Bytes
/
Copy pathTOANDFRO.cpp
File metadata and controls
51 lines (41 loc) · 780 Bytes
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
// AC , ALGO : Adhoc, Implementation.
#include<cstdio>
#include<cstring>
using namespace std ;
int main( )
{
char str[300] ;
int c , r , n , i , j , flag , ctr ;
scanf("%d",&c) ;
while( c != 0 )
{
scanf("%s",str) ;
n = strlen( str ) ;
r = n / c ;
char a[r][c+1] ;
flag = -1 ;
for( i = ctr = 0 ; i < r && ctr < n ; i++ )
{
flag *= -1 ;
if( flag == 1 )
{
for( j = 0 ; j < c ; j++ )
a[i][j] = str[ctr++] ;
a[i][j] = '\0' ;
}
else
{
for( j = c - 1 ; j >= 0 ; j-- )
a[i][j] = str[ctr++] ;
}
}
for( i = 0 ; i < c ; i++ )
{
for( j = 0 ; j < r ; j++ )
printf("%c",a[j][i]) ;
}
printf("\n") ;
scanf("%d",&c) ;
}
return 0 ;
}