fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void search_min_id(int a[3][4],int i1,int j1,int i2,int j2,int *xid,int *yid)
  5. {
  6. int min,x,y;
  7. *xid=i1;
  8. *yid=j1;
  9. min=a[i1][j1];
  10. for (x=i1;x<=i2;x++)
  11. {
  12. for (y=j1;y<=j2;y++)
  13. {
  14. if(min>a[x][y])
  15. {
  16. min=a[x][y];
  17. *xid=x;
  18. *yid=y;
  19. }
  20. }
  21. }
  22. return;
  23. }
  24.  
  25. int main()
  26. {
  27. int x,i1=0,i2=0,j1=0,j2=0,a[3][4],N=3,M=4;
  28.  
  29. for (int i = 0; i < N; ++i)
  30. {
  31. for (int j = 0; j < M; ++j)
  32. {
  33. cin >> a[i][j];
  34. }
  35. }
  36. search_min_id(a,0,0,2,1,&i1,&j1); // Исправлено
  37. search_min_id(a,0,2,2,3,&i2,&j2); // тут
  38. x=a[i1][j1];
  39. a[i1][j1]=a[i2][j2];
  40. a[i2][j2]=x;
  41.  
  42. for (int i = 0; i < N; ++i)
  43. {
  44. for (int j = 0; j < M; ++j)
  45. {
  46. cout << a[i][j] << "\t";
  47. }
  48.  
  49. cout << "\n";
  50. }
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0s 3300KB
stdin
1 2 3 4 5 6 7 8 9 10 11 12
stdout
3	2	1	4	
5	6	7	8	
9	10	11	12