fork download
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int plansza[10][10];
  10. srand(time(NULL));
  11. for(int x=0; x<10;x++)
  12. {
  13. for(int y=0; y<10; y++)
  14. plansza[x][y]=rand()%10; //wypelnianie tablicy losowymi wartosciami z przedzialu (0,9)
  15. }
  16. for(int x=0; x<10;x++)
  17. {
  18. for(int y=0; y<10; y++)
  19. cout<<plansza[x][y]<<" ";
  20. cout<<endl;
  21. }
  22. int pozycja, suma=0,tmx=0,tmp;
  23.  
  24. for(int y=0; y<10; y++)
  25. {
  26. pozycja=0;
  27.  
  28. if(y==0)
  29. {
  30. for(int x=0; x<10 ; x++)
  31. {
  32.  
  33. if(plansza[x][y]>pozycja)
  34. {
  35. pozycja=plansza[x][y];
  36. tmx=x;
  37. }
  38.  
  39. }
  40. }
  41. else
  42. {
  43. if(tmx>0 && tmx<9)
  44.  
  45. {
  46. for(int x=tmx-1; x<=tmx+1; x++)
  47. {
  48. if(plansza[x][y]>pozycja)
  49. {
  50. pozycja=plansza[x][y];
  51. //tmx=x;
  52. tmp=x;
  53. }
  54. else if(plansza[x][y]==pozycja) continue;
  55. }
  56. tmx=tmp;
  57.  
  58. }
  59. else if(tmx==0)
  60. {
  61. for(int x=tmx; x<=tmx+1; x++)
  62. {
  63. if(plansza[x][y]>pozycja)
  64. {
  65. pozycja=plansza[x][y];
  66. //tmx=x;
  67. tmp=x;
  68. }
  69. }
  70. tmx=tmp;
  71.  
  72. }
  73. else if(tmx==9)
  74. {
  75. for(int x=tmx; x>=tmx-1; x--)
  76. {
  77. if(plansza[x][y]>pozycja)
  78. {
  79. pozycja=plansza[x][y];
  80. //tmx=x;
  81. tmp=x;
  82. }
  83. }
  84. tmx=tmp;
  85.  
  86. }
  87.  
  88. }
  89. //cout<<"tmx= "<<tmx<<endl;
  90. // cout<<"pozycja="<<pozycja<<endl;
  91. suma+=pozycja;
  92. }
  93. cout<<"suma="<<suma;
  94.  
  95. return 0;
  96. }
  97.  
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
9 2 9 0 3 8 0 7 4 5 
7 5 3 8 0 6 3 0 2 6 
0 8 8 2 3 5 3 3 2 5 
0 3 7 2 3 3 0 6 0 4 
3 9 1 8 7 2 7 3 4 1 
1 5 9 9 9 4 4 5 7 6 
0 0 0 9 2 5 2 2 3 5 
8 7 4 0 7 4 4 4 7 0 
5 8 5 7 9 7 1 3 2 1 
2 2 1 4 3 5 1 6 7 5 
suma=62