Guest User

Untitled

a guest
Jul 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include<vector>
  4. #include<algorithm>
  5. #include<math.h>
  6. #include<cstring>
  7. #include<map>
  8. #include<set>
  9. #include <cctype>
  10. #include <cmath>
  11. #include <cstdio>
  12. #include<string>
  13. using namespace std;
  14.  
  15. int gcd(int a, int b) {
  16. if (a == 0)
  17. return b;
  18. return gcd(b%a, a);
  19. }
  20.  
  21. int main() {
  22. int n;
  23. string s;
  24. cin >> n;
  25. int k, a, b;
  26. double x;
  27. int css = 1;
  28. while (n != -1) {
  29. cin >> s;
  30. int size = s.size();
  31. int m = min(size-1, size - n);
  32. s += s.substr(m ,size);
  33. x = stod(s);
  34.  
  35. k = size - 2 - n;
  36.  
  37. b = pow(10, k + n) ;
  38. if (n != 0)
  39. b -= pow(10, k);
  40. a = pow(10, k + n)*x;
  41. if(n!=0)
  42. a-= (int)(pow(10, k)*x);
  43. int g = gcd(a, b);
  44. printf("Case %d: ", css); ++css;
  45.  
  46. printf("%d/%d\n", a/g,b/g);
  47. cin >> n;
  48. }
  49. system("pause");
  50. }
Add Comment
Please, Sign In to add comment