当前位置:   article > 正文

Hello World洛谷源神!_洛谷hello world 编程

洛谷hello world 编程

U264427 Hello World - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

思路:将无限循环小数转化为分数输出罢了

  1. #include<iostream>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<set>
  5. using namespace std;
  6. using ll = long long;
  7. ll gcd(ll x,ll y){
  8. return y?gcd(y,x%y):x;
  9. }
  10. int main ( ){
  11. ios::sync_with_stdio ( 0 ) , cin.tie ( 0 ) , cout.tie ( 0 );
  12. int t;cin>>t;
  13. while(t--){
  14. string s;cin>>s;
  15. ll w=0,r=0;
  16. for(int i=0;i<s.length();i++){
  17. w*=10;
  18. r*=10;
  19. w+=9;
  20. r+=s[i]-'0';
  21. }
  22. ll ans=gcd(w,r);
  23. ll l=r/ans;
  24. ll t=w/ans;
  25. cout<<l<<' '<<t<<'\n';
  26. }
  27. return 0;
  28. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/877671
推荐阅读
相关标签
  

闽ICP备14008679号