문제 링크입니다: https://www.acmicpc.net/problem/14914
14914번: 사과와 바나나 나눠주기
아름이가 나누어 줄 수 있는 경우를 모두 출력해야 하며, 각 경우마다 친구의 수, 사과 개수, 바나나 개수 차례로 한 줄에 각각 빈칸으로 구분하여 출력한다. 각 경우마다 중복없이 한 번만 출력되어야 하며, 경우의 순서는 친구의 수가 증가하는 순으로 한다.
www.acmicpc.net
a와 b의 공통 약수를 찾는 것이 핵심인 문제였습니다.
정답률이 말해주듯이 매우 쉬운 문제였습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int a, b; | |
cin >> a >> b; | |
vector<int> v; | |
//공통 약수 찾기 | |
for (int i = 1; i <= min(a, b); i++) | |
if (a%i == 0 && b%i == 0) | |
v.push_back(i); | |
for (int i = 0; i < v.size(); i++) | |
cout << v[i] << " " << a / v[i] << " " << b / v[i] << "\n"; | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 14911번 궁합 쌍 찾기 (0) | 2019.04.10 |
---|---|
백준 14913번 등차수열에서 항 번호 찾기 (0) | 2019.04.10 |
백준 2239번 스도쿠 (0) | 2019.04.08 |
백준 14890번 경사로 (2) | 2019.04.04 |
백준 6568번 귀도 반 로썸은 크리스마스날 심심하다고 파이썬을 만들었다 (2) | 2019.03.27 |