출처
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWcPjEuKAFgDFAU4
풀이
#include <bits/stdc++.h>
using namespace std;
int T, N;
int numbers[1000] = { 0 };
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> T;
for (int t = 1; t <= T; t++){
int result = -1;
cin >> N;
for (int n = 0; n < N; n++) {
cin >> numbers[n];
}
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
bool isIncreasing = true;
int current = numbers[i] * numbers[j];
if (result < current) {
int num = current;
while (num) {
if (num % 10 < (num / 10) % 10) {
isIncreasing = false;
break;
}
num /= 10;
}
if (isIncreasing) {
result = current;
}
}
}
}
cout << "#" << t << " " << result << endl;
memset(numbers, 0, sizeof(numbers));
}
}
완전 탐색 알고리즘으로 하나씩 검사한다.
반응형
'알고리즘' 카테고리의 다른 글
[C++] SWEA [S/W 문제해결 응용] 2일차 - 최대 상금 (0) | 2024.11.17 |
---|---|
[C++] SWEA 삼성시의 버스 노선 (0) | 2024.11.16 |
[C++] SWEA 0/1 Knapsack (0) | 2024.11.15 |
[C++] SWEA [SW 문제해결 기본] 4일차 - 거듭 제곱 (0) | 2024.11.14 |
[C++] SWEA 최장 경로 (0) | 2024.11.13 |