题解 AT1812 【テレビ】

题目大意

高桥君有一个宽(w),高(h)的电视机。
判定(w:h)(4:3)还是(16:9)


分析

我们可以理解成把一个比(w:h)化为最简整数比,也就是将(w:h)化简。那么,怎么化简一个比呢?我们都知道,比的基本性质是:“前项和后项同时扩大或缩小相同的数(0除外),比值不变”,我们可以利用这条性质,将分子与分母同时除以它们的最大公约数,再进行判断即可,具体实现见参考代码。


参考代码

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int w,h;
	cin>>w>>h;
	int x=__gcd(w,h);
	w=w/x;
	h=h/x;
	if(w==4)cout<<"4:3
";
	else cout<<"16:9
"; 
	return 0;
}
原文地址:https://www.cnblogs.com/tearing/p/12376352.html