fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ulli unsigned long long int
  4. #define lli long long int
  5. #define BIG(a,b) (a>b)?a:b
  6. #define SMALL(a,b) (a<b)?a:b
  7. #define FOR(i,o,n) for(auto i=o;i<n;i++)
  8. #define mod 1000000007
  9.  
  10. void pointer(string* str)
  11. {
  12.  
  13. cout<<*str<<endl;
  14. cout<<*(*str).begin()<<endl;
  15. cout<<*((*str).begin()+1)<<endl;
  16. cout<<str<<endl;
  17. *((*str).begin()+1)='n';
  18. }
  19.  
  20. void test(lli n)
  21. {
  22. string s,s1,s2;
  23. cin>>s;
  24. lli row = s.size()/n;
  25. vector<string> str;
  26. //cout<<s;
  27. for(auto j=0,i=0;i<s.size();i+=n,j++)
  28. {
  29. s1=s.substr(i,n);
  30. if(i%2!=0)
  31. reverse(s1.begin(),s1.end());
  32.  
  33. str.push_back(s1);
  34. //cout<<str[j]<<" "<<str[j][2]<<"\n";
  35. }
  36. FOR(i,0,n)
  37. {
  38. FOR(j,0,row)
  39. {
  40. s2+=str[j][i];
  41. }
  42. }
  43. cout<<s2<<"\n";
  44. }
  45.  
  46.  
  47. int main()
  48. {
  49. ios_base::sync_with_stdio( false );
  50. cin.tie(NULL);
  51.  
  52. lli t,n,flag=0,w,k;
  53.  
  54. //cin>>t;
  55. //while(t--)
  56. while(cin>>n && n!=0)
  57. {
  58.  
  59. test(n);
  60.  
  61. }
  62.  
  63. return 0;
  64. }
  65.  
Success #stdin #stdout 0s 4424KB
stdin
5
toioynnkpheleaigshareconhtomesnlewx
3
ttyohhieneesiaabss
0
stdout
theresnoplacelikehomeonasnowynightx
thisistheeasyoneab