728x90

https://www.acmicpc.net/problem/2562

#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 함수를 이용한 풀이
// */
view raw 2562.cpp hosted with ❤ by GitHub

+ Recent posts