Guest User

Untitled

a guest
Nov 22nd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int n;
  4. char map[51][51];
  5. char change[51][51];
  6. int dx[4]={1,-1,0,0};
  7. int dy[4]={0,0,1,-1};
  8. int cnt=0;
  9. void swap(char& a, char& b)
  10. {
  11. char temp=a;
  12. a=b;
  13. b=temp;
  14. }
  15. int main()
  16. {
  17. cin>>n;
  18. for(int i=0; i<n; i++)
  19. {
  20. for(int k=0; k<n; k++)
  21. {
  22. cin>>map[i][k];
  23. }
  24. }
  25. for(int i=0; i<n; i++)
  26. {
  27. for(int k=0; k<n; k++)
  28. {
  29. for(int j=0; j<4; j++)
  30. {
  31. int curi=i+dx[j];
  32. int curk=k+dy[j];
  33. int sum=0;
  34. if(curi>=0 && curi<n && curk>=0 && curk<n)
  35. {
  36. bool check=true;
  37. swap(map[i][k], map[curi][curk]);
  38. char na=map[i][k];
  39. for(int s=i-1; s>=0; s--)
  40. {
  41. if(na==map[s][k])
  42. sum++;
  43. else
  44. break;
  45. }
  46. for(int s=i+1; s<n; s++)
  47. {
  48. if(na==map[s][k])
  49. sum++;
  50. else
  51. break;
  52. }
  53. if(sum>cnt)
  54. cnt=sum;
  55. sum=0;
  56. for(int s=k-1; s>=0; s--)
  57. {
  58. if(na==map[i][s])
  59. sum++;
  60. else
  61. break;
  62. }
  63. for(int s=k+1; s<n; s++)
  64. {
  65. if(na==map[i][s])
  66. sum++;
  67. else
  68. break;
  69. }
  70. if(sum>cnt)
  71. cnt=sum;
  72. swap(map[i][k], map[curi][curk]);
  73.  
  74. }
  75. }
  76. }
  77. }
  78. cout<<cnt+1<<endl;
  79. }
Add Comment
Please, Sign In to add comment