fork(1) download
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cstdlib>
  6. #include<cctype>
  7. using namespace std;
  8.  
  9. const int SIZ = 210;
  10.  
  11. int main() {
  12. int t;
  13. scanf("%d\n", &t);
  14. char s[SIZ];
  15. while(t!=0) {
  16. int l, col, row;
  17. //scanf("%d\n", &col);
  18. col = t;
  19. for(l=0; l<SIZ; l++) {
  20. scanf("%c", &s[l]);
  21. if(s[l] == '\n') {
  22. l--;
  23. break;
  24. }
  25. }
  26. //cout<<"s "<<endl;
  27. /*for(int i=0; i<=l; i++)
  28. printf("%c", s[i]);
  29. cout<<endl;*/
  30. row = (l+1) / col;
  31. //cout<<"row "<<row<<" col "<<col<<endl;
  32. char s2[row][col];
  33. char s3[row][col];
  34. int k=0;
  35. for(int i=0; i<row; i++) {
  36. for(int j=0; j<col, k<=l; j++) {
  37. s2[i][j] = s[k];
  38. k++;
  39. }
  40. }
  41. //cout<<"s2 "<<endl;
  42. /*for(int i=0; i<row; i++) {
  43. for(int j=0; j<col; j++) {
  44. printf("%c", s2[i][j]);
  45. }
  46. cout<<endl;
  47. }
  48. cout<<endl;*/
  49. for(int i=0; i<row; i++) {
  50. for(int j=0; j<col; j++) {
  51. if(i%2!=0) {
  52. s3[i][j] = s2[i][col-1-j];
  53. }
  54. else {
  55. s3[i][j] = s2[i][j];
  56. }
  57. }
  58. }
  59. //cout<<"s3 "<<endl;
  60. for(int i=0; i<col; i++) {
  61. for(int j=0; j<row; j++) {
  62. printf("%c", s3[j][i]);
  63. }
  64. //cout<<endl;
  65. }
  66. cout<<endl;
  67. scanf("%d", &t);
  68. }
  69. return 0;
  70. }
Success #stdin #stdout 0s 2900KB
stdin
5
toioynnkpheleaigshareconhtomesnlewx
3
ttyohhieneesiaabss
0
stdout
theresnoplacelikehomeonasnowynightx

thisistheeasyoneab