Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main(int argc, const char * argv[]) {
- int A[5][5];
- int vector[9];
- printf("Input A\n");
- for (int i = 0; i < 5; i++) {
- for (int j = 0; j < 5; j++) {
- scanf("%d", &A[i][j]);
- }
- }
- int count = 0;
- int indexI = 4;
- int indexJ = 0;
- int currentMax = 0;
- while (indexI >= 0 && indexJ < 5) {
- for (int i = 0; i + indexI < 5 && i + indexJ < 5; i++) {
- // базовый случай
- if (i == 0) {
- currentMax = A[indexI + i][indexJ + i];
- }
- if (A[indexI + i][indexJ + i] > currentMax) {
- currentMax = A[indexI + i][indexJ + i];
- }
- }
- vector[count] = currentMax;
- count += 1;
- if (indexI > 0) {
- indexI -= 1;
- } else if (indexJ < 5) {
- indexJ += 1;
- }
- }
- for (int i = 0; i < 9; i++) {
- printf("%d ", vector[i]);
- }
- printf("\n");
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement