Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4. int main() {
  5. int n, m, i , j, tmp;
  6. cin >> n >> m;
  7. if ( n > m){
  8. tmp = m;
  9. }else{
  10. tmp = n;
  11. }
  12. int a[n][m];
  13. int lane;
  14. int start_lane = 0;
  15. int end_lane = n-1;
  16. int start_column = 0;
  17. int end_column = m-1;
  18. int numb = 1;
  19. for ( lane = 0; lane < (2*tmp); lane++){
  20. if ( lane%4 == 0){
  21. for ( j = start_column; j < end_column+1; j++){
  22. i = start_lane;
  23. a[i][j] = numb;
  24. numb++;
  25. //cout << i << j<<" ";
  26. //cout << setw(4)<<a[i][j];
  27. }
  28. start_lane++;//0+1 = 1
  29. //cout << endl;
  30. }else if ( lane%4 == 1){
  31. for ( i = start_lane; i < end_lane+1; i++){
  32. j = end_column;
  33. a[i][j] = numb;
  34. numb++;
  35. //cout << i << j<<" ";
  36. //cout << setw(4)<<a[i][j];
  37. }
  38. end_column--; // (m-1)-1
  39. //cout << endl;
  40. }else if ( lane%4 == 2){
  41. for ( j = end_column; j > start_column-1; j--){
  42. i = end_lane;
  43. a[i][j] = numb;
  44. numb++;
  45. //cout << i << j<<" ";
  46. //cout << setw(4)<<a[i][j];
  47. }
  48. end_lane--; //(n-1)-1
  49. //cout << endl;
  50. }else if ( lane%4 == 3){
  51. for ( i = end_lane; i > start_lane-1; i--){
  52. j = start_column;
  53. a[i][j] = numb;
  54. numb++;
  55. //cout << i << j<<" ";
  56. //cout << setw(4)<<a[i][j];
  57. }
  58. start_column++;// 0+1 = 1
  59. // cout << endl;
  60. }
  61. }
  62.  
  63. // ВЫВОД
  64. for ( i=0; i < n; i++){
  65. for ( j= 0; j< m; j++){
  66. cout << setw(4) << a[i][j];
  67. }
  68. cout<<endl;
  69. }
  70.  
  71.  
  72. // put your code here
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement