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. Vuex 页面刷新后store保存的数据会丢失 取cookie值

    在store.js中 export default new vuex.Store({ // 首先声明一个状态 state state:{ pcid: '', postList: [], } //更新状 ...

  2. 用jquery将多个页面中相似页面显示到一个页面并实现来回跳转

    今天遇到一个问题,客户说页面来回跳转太麻烦了,需要把相似的页面做到一个页面上去. 接下来说一下记录一下解决方法. 首先这是三个页面中相似的Div: <div class="wenti& ...

  3. [py]类的专有方法

    陆陆续续总结一些用到的类的特殊方法 看源码总会看到一些奇奇怪怪的写法: 掺杂着设计模式 https://coding.net/u/RuoYun/p/Python-design-pattern/git/ ...

  4. 【Python】-NO.96.Note.2.Python -【Python 基础】

    1.0.0 Summary Tittle:[Python]-NO.95.Note.1.Python -[Python 老男孩 基础]- Style:Python Series:Python Since ...

  5. 2018-2019-1 20189221《Linux内核原理与分析》第二周作业

    读书报告 <庖丁解牛Linux内核分析> 第 1 章 计算工作原理 1.1 存储程序计算机工作模型 1.2 x86-32汇编基础 1.3汇编一个简单的C语言程序并分析其汇编指令执行过程 因 ...

  6. xcode 报错Failed to load project at xxxx ,incompatible project version

    错误原因: 由于工程是低版本的Xcode建立的,在使用高版本的Xcode打开时会出现编译不了工程. 解决方法: 鼠标右击.xcodeproj文件 —>显示包内容 —>打开project.p ...

  7. git 不区分文件大小写的处理

  8. \Temporary ASP.NET Files\root\文件不断增长,如何处理?

    很久没有写博了.最近半年除了忙活布置新家和过年期间走亲访友之外,都是在公司处理一些项目中的杂事:连家里买的很多书都停下来没看了,感觉这段时间在事业和学习上一直都是忙忙碌碌,却又碌碌无为. 吐槽完,说正 ...

  9. Tensorflow实现LeNet-5、Saver保存与读取

    一. LeNet-5 LeNet-5是一种用于手写体字符识别的非常高效的卷积神经网络. 卷积神经网络能够很好的利用图像的结构信息. 卷积层的参数较少,这也是由卷积层的主要特性即局部连接和共享权重所决定 ...

  10. 解决Windows内存问题的两个小工具RamMap和VMMap

    解决Windows内存问题需要对操作系统的深入理解,同时对于如何运用Windows调试器或性能监控器要有工作认知.如果你正试着得到细节,诸如内核堆栈大小或硬盘内存消耗,你会需要调试器命令和内核数据架构 ...