SW Expert Academy
(SWEA c++)7102. 준홍이의 카드놀이
naeunchan
2020. 11. 23. 10:45
728x90
반응형
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
1 ~ N, 1 ~ M 까지의 카드가 있으므로,
모든 카드의 합을 구하여 나온 횟수를 카운팅하면 된다.
그 중 가장 많이 나온 합의 횟수를 *max_element()함수를 이용하여 찾은 후,
2 ~ 40 까지 카운팅 횟수와 같은 수를 출력해주면 된다.
2부터 시작하는 이유는 1 + 1 = 2 가 합의 최솟값이기 때문이다..!
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
for(int tc = 1; tc <= t; tc++)
{
int N, M, high = 0;
vector<int> v(40, 0);
cin >> N >> M;
for(int i = 1; i <= N; i++)
{
for(int j = 1; j <= M; j++)
v[i + j]++;
}
high = *max_element(v.begin(), v.end());
cout << "#" << tc << " ";
for(int i = 2; i <= 40; i++)
{
if(v[i] == high)
cout << i << " ";
}
cout << endl;
}
return 0;
}
728x90
반응형