Created
October 9, 2017 13:56
-
-
Save beohoang98/9ea592594c581bf777e1d6c8a5535566 to your computer and use it in GitHub Desktop.
This file contains 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> | |
using namespace std; | |
class PhanSo { | |
public: | |
int tu, mau; | |
PhanSo() { | |
tu = 0; | |
mau = 1; | |
} | |
PhanSo(int _tu, int _mau) { | |
tu = _tu; | |
mau = _mau; | |
if (mau == 0 && (tu = 0) && (mau = 1)); | |
} | |
int getUCLN() { | |
int a = tu, | |
b = mau, | |
r = a % b; | |
while (r > 0) { | |
a = b; | |
b = r; | |
r = a % b; | |
} | |
return b; | |
} | |
void rutGon() { | |
int ucln = getUCLN(); | |
tu /= ucln; | |
mau /= ucln; | |
} | |
PhanSo operator+ (const PhanSo& A) { | |
PhanSo tmp; | |
tmp.tu = tu*A.mau + mau*A.tu; | |
tmp.mau = mau*A.mau; | |
tmp.rutGon(); | |
return tmp; | |
} | |
}; | |
void main() { | |
freopen("INPUT.txt", "r", stdin); | |
freopen("OUTPUT.txt", "w", stdout); | |
//source | |
PhanSo Tong(0, 1); | |
PhanSo Chay(0, 1); | |
while (!feof(stdin)) { | |
cin >> Chay.tu >> Chay.mau; | |
Tong = Tong + Chay; | |
} | |
cout << Tong.tu << " " << Tong.mau; | |
fclose(stdin); | |
fclose(stdout); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment