题目 For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, diference, product and quotient. Input Specification: Each input file contains one test case, which gives in one line the two rational numb…
题目 Given N rational numbers in the form "numerator/denominator", you are supposed to calculate their sum. Input Specification: Each input file contains one test case. Each case starts with a positive integer N (<=100), followed in the next li…
简单题. 注意:读入的分数可能不是最简的.输出时也需要转换成最简. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<iostream> #include<algor…
输入为两个分数,让你计算+,-,*,\四种结果,并且输出对应的式子,分数要按带分数的格式k a/b输出如果为负数,则带分数两边要有括号如果除数为0,则式子中的结果输出Inf模拟题最好自己动手实现,考验细节处理,其它没啥好说的. #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; ]; ]; long long GC…
题意: 输入两个分数(分子分母各为一个整数中间用'/'分隔),输出它们的四则运算表达式.小数需要用"("和")"括起来,分母为0的话输出"Inf"(输入的分母保证不为0). trick: 测试点2很容易溢出,建议遇到乘法时先化简分数并且不要用相乘小于零来判断异号. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespac…
题目 Cutting an integer means to cut a K digits long integer Z into two integers of (K/2) digits long integers A and B. For example, afer cutting Z = 167334, we have A = 167 and B = 334. It is interesting to see that Z can be devided by the product of…
题目 Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3*5*6*7, where 5, 6, and 7 are the three consecutive numbers. Now given any positive N, you are supposed to find the ma…
1.注意在数字和string转化过程中,需要考虑数字不是只有一位的,如300转为"300",一开始卡在里这里, 测试用例: 24/8 100/10 24/11 300/11 2.该题用到了欧几里德算法求最小公约数gcd(a,b) 算法如下: //欧几里德算法求最大公约数gcd,其中a>b long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a%b); } AC代码如下: //#include&l…
题目 本题要求编写程序,计算2个有理数的和.差.积.商. 输⼊格式: 输⼊在⼀⾏中按照"a1/b1 a2/b2"的格式给出两个分数形式的有理数,其中分⼦和分⺟全是整型范围内的整数,负号只可能出现在分⼦前,分⺟不为0. 输出格式: 分别在4⾏中按照"有理数1 运算符 有理数2 = 结果"的格式顺序输出2个有理数的和.差.积.商.注意输出的每个有理数必须是该有理数的最简形式"k a/b",其中k是整数部分,a/b是最简分数部分:若为负数,则须加括号:…
1088. Rational Arithmetic (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, product and quotient. Input Spe…