fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int H, L, move=0, skip=0;
  6. string s;
  7. cin>>H>>L;
  8. cin.ignore();
  9. cin>>s;
  10. int size = H*L;//size of the grid
  11. vector <char> vec(size);//declaring the vector as the size of the grid
  12. for(int i=0; i+skip<s.length(); i++){//looping to input the chars into the vector
  13. //T"h"eQuic"k"BrownFoxJumpsOverT"h"eLazyDog
  14. //eQuick
  15. cout<<move<<"\n";
  16. if(s[i]=='h'){
  17. if(i+move-skip+1%L!=1 || i+move-skip+1%L!=0){
  18. move--;
  19. skip++;
  20. vec[i+move]=s[i+skip];
  21. }
  22. else{
  23. move+=L-1;
  24. skip++;
  25. vec[i+move]=s[i+skip];
  26. }
  27. }
  28. else if(s[i]=='l'){
  29. if(i+move-skip+1%L!=1 || i+move-skip+1%L!=0){
  30. move++;
  31. skip++;
  32. vec[i+move]=s[i+skip];
  33. }
  34. else{
  35. move-=L-1;
  36. skip++;
  37. vec[i+move]=s[i+skip];
  38. }
  39. }
  40. else if(s[i]=='j'){
  41. if(i+move-skip+1<L){
  42. move+=5;
  43. skip++;
  44. vec[i+move]=s[i+skip];
  45. }
  46. else{
  47. move-=(size)-(i+1);
  48. skip++;
  49. vec[i+move]=s[i+skip];
  50. }
  51. }
  52. else if(s[i]=='k'){
  53. if(i+1+move-skip>size-L){
  54. move-=5;
  55. skip++;
  56. vec[i+move]=s[i+skip];
  57. }
  58. else{
  59. move+=(size)-(i+1);
  60. skip++;
  61. vec[i+move]=s[i+skip];
  62. }
  63. }
  64. else{
  65. vec[i+move]=s[i+skip];
  66. }
  67. }
  68. for(int i=0; i<vec.size(); i++){
  69. cout<<vec[i];
  70. if(i+1==L){
  71. cout<<"\n";
  72. }
  73. }
  74. if(vec.size()<size){
  75. for(int i=0; i<size-vec.size(); i++){
  76. cout<<".";
  77. }
  78. }
  79. }
  80.  
Success #stdin #stdout 0.01s 5284KB
stdin
3 5
TheQuickBrownFoxJumpsOverTheLazyDog
stdout
zyDog1
-1
-1
-1
-1
-1
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
5
5
5
5
5
eQuic
kro