알고리즘/BOJ

백준 2566번 최댓값

꾸준함. 2021. 4. 25. 00:49

문제 링크입니다: www.acmicpc.net/problem/2566

 

2566번: 최댓값

첫째 줄에 최댓값을 출력하고, 둘째 줄에 최댓값이 위치한 행 번호와 열 번호를 빈칸을 사이에 두고 차례로 출력한다. 최댓값이 두 개 이상인 경우 그 중 한 곳의 위치를 출력한다.

www.acmicpc.net

간단한 구현 문제였습니다.

 

#include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 9;
typedef struct
{
int value;
pair<int, int> coord;
}Number;
bool cmp(Number a, Number b)
{
return a.value > b.value;
}
int main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
Number arr[MAX * MAX];
int idx = 0;
for (int i = 1; i <= MAX; i++)
{
for (int j = 1; j <= MAX; j++)
{
int value;
cin >> value;
arr[idx++] = { value, {i, j} };
}
}
sort(arr, arr + MAX * MAX, cmp);
Number result = arr[0];
cout << result.value << "\n";
cout << result.coord.first << " " << result.coord.second << "\n";
return 0;
}
view raw .cpp hosted with ❤ by GitHub

 

개발환경:Visual Studio 2017

 

지적, 조언, 질문 환영입니다! 댓글 남겨주세요~

반응형

'알고리즘 > BOJ' 카테고리의 다른 글

백준 2720번 세탁소 사장 동혁  (0) 2021.04.25
백준 2576번 홀수  (0) 2021.04.25
백준 21553번 암호 만들기  (0) 2021.04.24
백준 2547번 사탕 선생 고창영  (0) 2021.04.23
[KOI 초등부] 백준 2511번 카드놀이  (0) 2021.04.23