14490번: 백대열
n과 m이 :을 사이에 두고 주어진다. (1 ≤ n, m ≤ 100,000,000)
www.acmicpc.net
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int gcd(int a, int b) {
if (b == 0) return a;
else return gcd(b, a % b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
string s, a, b;
cin >> s;
bool flag = false;
for (int i = 0; i < s.length(); i++) {
if (s[i] == ':') {
flag = true;
continue;
} else if (!flag) a += s[i];
else b += s[i];
}
int x, y, mod;
x = stoi(a);
y = stoi(b);
mod = gcd(x, y);
cout << x / mod << ':' << y / mod;
}
'Algorithm 🧑🏻💻 > 백준(BOJ)' 카테고리의 다른 글
[백준,c++] 9465번 - 스티커 (0) | 2021.11.10 |
---|---|
[백준,c++] 14496번 - 그대,그머가 되어 (0) | 2021.11.07 |
[백준,c++] 14495번 - 피보나치 비스무리한 수열 (0) | 2021.11.07 |
[백준,c++] 14467번 - 소가 길을 건너간 이유1 (0) | 2021.11.07 |
[백준,c++] 14425번 - 문자열 집합 (0) | 2021.11.07 |
[백준,c++] 14391번 - 종이 조각 (0) | 2021.11.07 |
댓글