赞
踩
U264427 Hello World - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
思路:将无限循环小数转化为分数输出罢了
- #include<iostream>
- #include<cstring>
- #include<cmath>
- #include<set>
- using namespace std;
- using ll = long long;
- ll gcd(ll x,ll y){
- return y?gcd(y,x%y):x;
- }
- int main ( ){
- ios::sync_with_stdio ( 0 ) , cin.tie ( 0 ) , cout.tie ( 0 );
- int t;cin>>t;
- while(t--){
- string s;cin>>s;
- ll w=0,r=0;
-
-
- for(int i=0;i<s.length();i++){
- w*=10;
- r*=10;
- w+=9;
- r+=s[i]-'0';
-
- }
- ll ans=gcd(w,r);
-
- ll l=r/ans;
- ll t=w/ans;
- cout<<l<<' '<<t<<'\n';
- }
-
- return 0;
- }
-
-

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。