관리 메뉴

사적공간

구조체로 함수 리턴받기 본문

KNOU_CS/C++

구조체로 함수 리턴받기

2sac 2024. 12. 13. 15:09

 

#include <iostream>
#include <cstring>
using namespace std;

struct YX {
    int y;
    int x;
};

YX max(int(&arr)[2][3]) {
    int max = arr[0][0];
    YX ma; 
    for (int y = 0; y < 2; y++) {
        for (int x = 0; x < 3; x++) {
            if (arr[y][x] >= max)
            {
             max = arr[y][x];
             ma.y = y;
             ma.x = x; 
            }
        }
    }

    return ma; 
}


YX min(int(&arr)[2][3]) {
    int min = arr[0][0];
    YX mi; 
    for (int y = 0; y < 2; y++) {
        for (int x = 0; x < 3; x++) {
            if (arr[y][x] <= min)
            {
             min = arr[y][x];
             mi.y = y;
             mi.x = x; 
            }
        }
    }
    return mi; 
}


int main() {


    int arr[2][3];
    for (int y = 0; y < 2; y++) {
        for (int x = 0; x < 3; x++) {
            cin >> arr[y][x]; 
        }
    }


    YX a = max(arr);
    YX b = min(arr); 

    cout << "(" << a.y << "," << a.x << ")" << endl;
    cout << "(" << b.y << "," << b.x << ")" << endl;


    return 0;
}