[SWEA] C++ 7829. 보물왕 태혁(D4)

swb·2022년 11월 15일
0

SWEA

목록 보기
11/19

문제 바로가기

접근방법

  1. 이게 왜 D4지..?
  2. 가장 큰 값과 가장 작은 값을 곱하면 답이 나올 수 밖에,,

풀이

#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;

int test_case, T, P, max, a, answer;
vector<int> v;

void input() {
	for (int i = 0; i < P; i++) {
		cin >> a;
		v.push_back(a);
	}
}

int	GetMaxNum() {
	if (P == 1)
		return v[0] * v[0];
	else
		return v[0] * v[v.size() - 1];
}

int main() {
	cin >> T;

	for (test_case = 1; test_case <= T; test_case++) {
		cin >> P;

		input(); 
		sort(v.begin(), v.end());

		cout << "#" << test_case << " " << GetMaxNum() << "\n";
		v.clear();
	}
	return 0;
}
profile
개발 시작

0개의 댓글