1088
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1088相关的知识,希望对你有一定的参考价值。
a x b = c
将a,b,c用out统一输出
AC代码:
#include <cstdio> #include <string> using namespace std; long long gcd(long long x,long long y){ if(x == 0) return y; if(y == 0) return x; if(x < 0) x = -x; if(y < 0) y = -y; long long max,min; max = x > y ? x : y; min = x > y ? y : x; while(max % min != 0){ long long tmp(min); min = max % min; max = tmp; } return min; } void out(long long an,long long ad){ if(ad == 0){ printf("Inf"); return; } if(ad < 0){ ad = -ad; an = -an; } long long ai,g; ai = an / ad; an = an - ai * ad; g = gcd(an,ad); an /= g; ad /= g; if(ai != 0){ an = an > -an ? an : -an; if(an != 0){ if(ai < 0){ printf("(%lld %lld/%lld)",ai,an,ad); } else{ printf("%lld %lld/%lld",ai,an,ad); } } else{ if(ai < 0){ printf("(%lld)",ai); } else printf("%lld",ai); } } else{ if(an == 0) printf("0"); else if(an < 0) printf("(%lld/%lld)",an,ad); else printf("%lld/%lld",an,ad); } } int main(){ long long an,ad,bn,bd; scanf("%lld/%lld %lld/%lld",&an,&ad,&bn,&bd); out(an,ad); printf(" + "); out(bn,bd); printf(" = "); out(an*bd+bn*ad,ad*bd); printf("\n"); out(an,ad); printf(" - "); out(bn,bd); printf(" = "); out(an*bd-bn*ad,ad*bd); printf("\n"); out(an,ad); printf(" * "); out(bn,bd); printf(" = "); out(an*bn,ad*bd); printf("\n"); out(an,ad); printf(" / "); out(bn,bd); printf(" = "); out(an*bd,ad*bn); printf("\n"); return 0; }
以上是关于1088的主要内容,如果未能解决你的问题,请参考以下文章
1088. Rational Arithmetic (20)——PAT (Advanced Level) Practise
1088. Rational Arithmetic (20)——PAT (Advanced Level) Practise