Input

The first line of input contains one integer, giving the number of operations to perform.

Then follow the operations, one per line, each of the form x1 y1 op x2 y2. Here, −109≤x1,y1,x2,y2<109 are integers, indicating that the operands are x1/y1 and x2/y2. The operator op is one of ’+’, ’−’, ’∗’, ’/’, indicating which operation to perform.

You may assume that y1≠0, y2≠0, and that x2≠0 for division operations.

Output

For each operation in each test case, output the result of performing the indicated operation, in shortest terms, in the form indicated.

Sample Input 1 Sample Output 1
4
1 3 + 1 2
1 3 - 1 2
123 287 / 81 -82
12 -3 * -1 -1
5 / 6
-1 / 6
-82 / 189
-4 / 1

题目不解释了,看样例也能懂。

注意用long long。

 //Asimple
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m, s, res, ans, len, T, k, num;
ll a, b, c, d;
char ch; ll gcd(ll a, ll b ) {
return b==?a:gcd(b, a%b);
} void print(ll num, ll den){
bool pos = (num> && den>) || (num< && den<);
if (num<) num = -num;
if (den<) den = -den;
ll d = gcd(num,den);
num /= d , den /= d;
if (num== || den==) cout << "0 / 1" << endl;
else cout << (pos?"":"-") << num << " / " << den << endl;
} void add_sub(ll x1, ll y1, ll x2, ll y2, int state){
ll num = x1*y2 + state*x2*y1;
ll den = y1*y2;
print(num,den);
} void mul(ll x1, ll y1, ll x2, ll y2){
ll num = x1*x2;
ll den = y1*y2;
print(num,den);
} void input() {
cin >> T;
while( T -- ) {
cin >> a >> b >> ch >> c >> d;
switch(ch){
case '+':
add_sub(a, b, c, d,);
break;
case '-':
add_sub(a, b, c, d, -);
break;
case '*':
mul(a, b, c, d);
break;
case '/':
mul(a, b, d, c);
break;
}
}
} int main(){
input();
return ;
}

Kattis之旅——Rational Arithmetic的更多相关文章

  1. PAT1088:Rational Arithmetic

    1088. Rational Arithmetic (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue F ...

  2. PAT 1088 Rational Arithmetic[模拟分数的加减乘除][难]

    1088 Rational Arithmetic(20 分) For two rational numbers, your task is to implement the basic arithme ...

  3. pat1088. Rational Arithmetic (20)

    1088. Rational Arithmetic (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue F ...

  4. PAT_A1088#Rational Arithmetic

    Source: PAT A1088 Rational Arithmetic (20 分) Description: For two rational numbers, your task is to ...

  5. A1088. Rational Arithmetic

    For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate the ...

  6. Kattis之旅——Prime Reduction

    A prime number p≥2 is an integer which is evenly divisible by only two integers: 1 and p. A composit ...

  7. 1088 Rational Arithmetic(20 分)

    For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate the ...

  8. PAT Rational Arithmetic (20)

    题目描写叙述 For two rational numbers, your task is to implement the basic arithmetics, that is, to calcul ...

  9. PAT 1088. Rational Arithmetic

    For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate the ...

随机推荐

  1. 第1章 CLR的执行模型

    1.1将源代码编译成托管代码模块

  2. [LeetCode] 590. N-ary Tree Postorder Traversal_Easy

    Given an n-ary tree, return the postorder traversal of its nodes' values. For example, given a 3-ary ...

  3. [Java in NetBeans] Lesson 12. Arrays

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: 1. Array: container that holds a fixed number of values of the sam ...

  4. plt.contour 与 plt.contourf

    contour:轮廓,等高线 1.为等高线上注明等高线的含义: cs = plt.contour(x, y, z) plt.clabel(cs, inline=True, fontsize=10)#i ...

  5. iOS 开发笔记 - 开发中如何实现自动检测更新APP

    1.获取当前项目APP版本号 2.拿到AppStore项目版本号 3.对比版本号,实现更新功能 直接上代码: #import "ViewController.h" //1一定要先配 ...

  6. JAVA编程思想学习笔记7-chap19-21-斗之气7段

    1.枚举 2.内置三种注解 @Override @Deprecated @SuppressWarnings 3.元注解:用于注解其它注解 4.注解处理器:通过反射 5.创建线程的两种方式 实现Runn ...

  7. vue路由(一个包含重定向、嵌套路由、懒加载的main.js如下)and 路由跳转传参的query和params的异同

    import Vue from 'vue'import VueRouter from 'vue-router'import App from './App'Vue.use(VueRouter)cons ...

  8. VirtualBox下扩容vdi文件

    VirtualBox下扩容vdi文件 版本:VirtualBox 5.0.14 之前VirtualBox创建的虚拟机的vdi文件过小,无法满足新的实验需求,扩容vdi文件的方法如下: 比如我这里将RH ...

  9. MyBatis基础入门《七》查询参数传入对象

    MyBatis基础入门<七>查询参数传入对象 描述: 在执行查询语句的时候,传入的参数是一个对象,依据对象的属性,进行检索数据.此时,书写SQL语句中的条件时,其参数需要和对象中的属性保持 ...

  10. spark-shell下有提示了,但是发现不能退格

    配好了Spark集群后,先用pyspark写了两个小例子,但是发现Tab键没有提示,于是打算转到scala上试试,在spark-shell下有提示了,但是发现不能退格,而且提示也不是复写,而是追加,这 ...