Algorithm 🧑🏻💻/백준(BOJ)
[백준,c++] 14490번 - 백대열
dkswnkk
2021. 11. 7. 23:14
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;
}