Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int r,c;
  7. cin >> r >>c;
  8. int a[r][c];
  9. for(int i=0;i<r;i++)
  10. {
  11. for(int j=0;j<c;j++)
  12. {
  13. cin >> a[i][j];
  14. }
  15. }
  16. for(int i=0;i<r;i++)
  17. {
  18. for(int j=0;j<c;j++)
  19. {
  20. cout << a[i][j] << "\t";
  21. }
  22. cout << endl;
  23.  
  24. }
  25. int s_r=0,s_c=0,e_r=r-1,e_c=c-1;
  26. while(s_r<=e_r && s_c<=e_c)
  27. {
  28. for(int i=s_r;i<=e_c;i++)
  29. {
  30. cout << a[s_r][i] << "\t";
  31. }
  32. s_r++;
  33. for(int i=s_r;i<=e_r;i++)
  34. {
  35. cout << a[i][e_c] << "\t";
  36. }
  37. e_c--;
  38. if(s_r<=e_r)
  39. {
  40. for(int i=e_c;i>=s_c;i--)
  41. {
  42. cout << a[e_r][i]<< "\t";
  43. }
  44. e_r--;
  45. }
  46. if(s_c<=e_c)
  47. {
  48. for(int i=e_r;i>=s_r;i--)
  49. {
  50. cout << a[i][s_c] << "\t";
  51. }
  52. s_c--;
  53. }
  54.  
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement