zoukankan      html  css  js  c++  java
  • a/b + c/d

    a/b + c/d

    Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)

    Total Submission(s) : 0   Accepted Submission(s) : 0

    Font: Times New Roman | Verdana | Georgia

     Font Size: ← →

    Problem Description

    给你2个分数,求他们的和,并要求和为最简形式。  

    Input

    输入首先包含一个正整数T(T<=1000),表示有T组测试数据,然后是T行数据,每行包含四个正整数a,b,c,d(0<a,b,c,d<1000),表示两个分数a/b 和 c/d。  

    Output

    对于每组测试数据,输出两个整数e和f,表示a/b + c/d的最简化结果是e/f,每组输出占一行。  

    Sample Input

    2 1 2 1 3 4 3 2 3

     Sample Output

    5 6 2 1

     Source

    《ACM程序设计》短学期考试_软件工程及其他专业

    代码:

    #include<iostream> using namespace std;

    int main() {

     int n;  cin>>n;

     while(n--)  

    {   int a,b,c,d;   int e,f;//记录结果的分子 分母;   cin>>a>>b>>c>>d;   f=b*d;//通分   e=a*d+c*b;//分子之和  

     int m=2;   int k=e;  

     for(m;m<=k;m++)  

     {    while(e%m==0&&f%m==0)//能够被分子分母整除;   

     {     e=e/m;     f=f/m;            

     }    

    k=e;      

      }   

    cout<<e<<" "<<f<<endl;

         }

    return 0; }

  • 相关阅读:
    shell中的for循环
    tty相关
    udev规则
    find中perm参数
    日志级别的选择:Debug、Info、Warn、Error还是Fatal
    云计算、云存储、大数据
    JSON数据解析(python3.4)
    38、友盟统计
    37、iamgeview 图层叠加
    36、imageview的坑
  • 原文地址:https://www.cnblogs.com/2013lzm/p/3188653.html
Copyright © 2011-2022 走看看