hdu2503:a/b + c/d
2016-05-21 23:29
232 查看
//hdu2503
#include <iostream>
#include <stdio.h>
using namespace std;
int gcd(int a, int b)
{
int t, r;
if(a > b)
{
t = b;
b = a;
a = t;
}
while(a)
{
r = b % a;
b = a;
a = r;
}
return b;
}
int main()
{
int T;
cin >> T;
int a, b, c, d;
int e, f, r;
//a/b + c/d = e/f
while(T--)
{
cin >> a >> b >> c >> d;
f = b * d;
e = a * d + b * c;
r = gcd(e, f);
cout << e / r << ' ' << f / r << endl;
}
return 0;
}
//hdu2503
#include <iostream>
#include <stdio.h>
using namespace std;
int gcd(int a, int b)
{
int t, r;
if(a > b)
{
t = b;
b = a;
a = t;
}
while(a)
{
r = b % a;
b = a;
a = r;
}
return b;
}
int main()
{
int T;
cin >> T;
int a, b, c, d;
int e, f, r;
//a/b + c/d = e/f
while(T--)
{
cin >> a >> b >> c >> d;
f = b * d;
e = a * d + b * c;
r = gcd(e, f);
cout << e / r << ' ' << f / r << endl;
}
return 0;
}
相关文章推荐
- 3180: [Coci2012]ograda 贪心
- HuaXinIM聊项目阶段总结七(收发文件实现)
- 用动画切换按钮的状态
- 【编译器】斯坦福公开课学习2
- windows文件浏览器选项
- Android自定义View之组合控件-仿电商app顶部栏
- 剑指Offer----面试题七:用两个栈实现队列
- 数据库更替数据sql语句
- mybatis的批量删除
- offer--链表反转和从尾到头打印链表
- 3463: [COCI2012] Inspector 分块+凸壳
- 使用python编写工具处理DHT22驱动调试信息
- vmware workstation 12安装centos 6.5
- HDU 5373 (模拟 水~)
- mysql数据库自动备份脚本分享
- 大端与小端存储模式详解
- imindmap、Mindmanager、mindmapper、xmind比较
- 带你玩转Visual Studio——性能分析与优化
- 为什么有些网页既设背景图又设背景色?
- 3181: [Coci2012]BROJ 找规律