step1_入门_ACM水题 a/b + c/d 【最大公约数】

牢记于心

代码
int fun(int a, int b){
    if(b==0)
        return a;
    else
        return fun(b, a%b);
}//迭代函数

用个题强化一下

http://acm.hdu.edu.cn/showproblem.php?pid=2503

代码

#include
using namespace std;
int gcd(int a,int b){
	while(a!=b){
		if(a>b)a-=b;
		else b-=a;
	}
	return a;
}
int main(){
	int T;cin>>T;
	while(T--){
		int a,b;cin>>a>>b;
		int c,d;cin>>c>>d;
		int e,f;
		e=a*d+b*c;
		f=b*d;
		int g=gcd(e,f);
		cout<

 

你可能感兴趣的:(2018年为准备CCF,CSP的第二遍刷题)