728x90

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define N 9 | |
using namespace std; | |
int main() { | |
ios::sync_with_stdio(false), cin.tie(nullptr); | |
int indexOfMax = 0, a[N] = {}; | |
for (int i = 0; i < N; i++) { | |
cin >> a[i]; | |
if (a[indexOfMax] < a[i]) indexOfMax = i; | |
} | |
cout << a[indexOfMax] << '\n' << indexOfMax + 1; | |
} | |
/* | |
최댓값(2562) | |
O(N) | |
순차 검색을 이용해 최댓값 찾기 | |
배열의 index를 0부터 시작하므로, 출력할 때 +1 해주기 | |
*/ | |
// #include <bits/stdc++.h> | |
// using namespace std; | |
// int input, maxValue, maxIndex; | |
// int main(void) { | |
// ios::sync_with_stdio(false), cin.tie(nullptr); | |
// for (int i = 1; i < 10; i++) { | |
// cin >> input; | |
// if (maxValue < input) { | |
// maxValue = input; | |
// maxIndex = i; | |
// } | |
// } | |
// cout << maxValue << '\n' << maxIndex; | |
// } | |
// Authored by : BaaaaaaaaaaarkingDog | |
// Co-authored by : - | |
// http://boj.kr/359583ea75ef49f7acf7c5564827ebba | |
// #include <bits/stdc++.h> | |
// using namespace std; | |
// int a[9]; | |
// int main(void) { | |
// ios::sync_with_stdio(0); | |
// cin.tie(0); | |
// for (int i = 0; i < 9; i++) cin >> a[i]; | |
// cout << *max_element(a, a + 9) << '\n'; | |
// cout << max_element(a, a + 9) - a + 1; | |
// } | |
// /* | |
// max_element 함수를 이용한 풀이 | |
// */ |
'Algorithm > C&C++' 카테고리의 다른 글
백준 2587번: 대표값2(c/c++, c/cpp) (0) | 2021.10.06 |
---|---|
백준 2576번: 홀수(c/c++, c/cpp) (0) | 2021.10.05 |
백준 2490번: 윷놀이(c/c++, c/cpp) (0) | 2021.10.05 |
백준 2480번: 주사위 세개(c/c++, c/cpp) (0) | 2021.09.29 |
백준 2753번: 윤년(c++) (0) | 2021.09.29 |