Advertisement
Guest User

Untitled

a guest
Dec 7th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main(int argc, const char * argv[]) {
  4. int A[5][5];
  5. int vector[9];
  6.  
  7. printf("Input A\n");
  8. for (int i = 0; i < 5; i++) {
  9. for (int j = 0; j < 5; j++) {
  10. scanf("%d", &A[i][j]);
  11. }
  12. }
  13.  
  14. int count = 0;
  15. int indexI = 4;
  16. int indexJ = 0;
  17. int currentMax = 0;
  18. while (indexI >= 0 && indexJ < 5) {
  19. for (int i = 0; i + indexI < 5 && i + indexJ < 5; i++) {
  20. // базовый случай
  21. if (i == 0) {
  22. currentMax = A[indexI + i][indexJ + i];
  23. }
  24.  
  25. if (A[indexI + i][indexJ + i] > currentMax) {
  26. currentMax = A[indexI + i][indexJ + i];
  27. }
  28. }
  29.  
  30. vector[count] = currentMax;
  31. count += 1;
  32.  
  33. if (indexI > 0) {
  34. indexI -= 1;
  35. } else if (indexJ < 5) {
  36. indexJ += 1;
  37. }
  38. }
  39.  
  40. for (int i = 0; i < 9; i++) {
  41. printf("%d ", vector[i]);
  42. }
  43.  
  44. printf("\n");
  45. getchar();
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement