수 입력 범위가 0보다 크거나 같은데 만약 최댓값이 0이면 갱신이 안될거 같네요
2566번 - 최댓값
#include <iostream>
int main(int argc, char *argv[]) {
short arr[9][9], maxIndex[2];
short max = -1;
for(int i = 0; i < 9; i++){
for(int j = 0; j < 9; j++){
std::cin >> arr[i][j];
}
}
for(int i = 0; i < 9; i++){
for(int j = 0; j < 9; j++){
if(arr[i][j] > max){
max = arr[i][j];
maxIndex[0] = i+1;
maxIndex[1] = j+1;
}
}
}
std::cout << max << std::endl;
std::cout << maxIndex[0] << " " << maxIndex[1];
return 0;
}
말해주신 대로 max 초깃값을 -1로 설정하니 해결됐습니다!
감사합니다!
댓글을 작성하려면 로그인해야 합니다.
dksh_2023010518 2년 전
알려주시면 감사하겠습니다!