Advertisement
Saleh127

UVA 332

Sep 16th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. cout.tie(0);
  10.  
  11. ll p,tt=1;
  12.  
  13. while(cin>>p)
  14. {
  15. if(p==-1) break;
  16. string x;
  17. ll num1=0,dos1=1,dos2=1,num2=0,ans,i,j,k,l;
  18.  
  19. cin>>x;
  20.  
  21. cout<<"Case "<<tt++<<": ";
  22.  
  23. for(i=2; i<x.size(); i++)
  24. {
  25. num1=(num1*10)+(x[i]-'0');
  26. dos1*=10;
  27. }
  28.  
  29.  
  30. if(p==0)
  31. {
  32. k=__gcd(num1,dos1);
  33. cout<<num1/k<<"/"<<dos1/k<<endl;
  34. }
  35. else
  36. {
  37. l=x.size()-p;
  38. for(i=2; i<l; i++)
  39. {
  40. num2=(num2*10)+(x[i]-'0');
  41. dos2*=10;
  42. }
  43. num1-=num2;
  44. dos1-=dos2;
  45. k=__gcd(num1,dos1);
  46. cout<<num1/k<<"/"<<dos1/k<<endl;
  47. }
  48.  
  49. }
  50.  
  51. return 0;
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement