Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include<vector>
- #include<algorithm>
- #include<math.h>
- #include<cstring>
- #include<map>
- #include<set>
- #include <cctype>
- #include <cmath>
- #include <cstdio>
- #include<string>
- using namespace std;
- int gcd(int a, int b) {
- if (a == 0)
- return b;
- return gcd(b%a, a);
- }
- int main() {
- int n;
- string s;
- cin >> n;
- int k, a, b;
- double x;
- int css = 1;
- while (n != -1) {
- cin >> s;
- int size = s.size();
- int m = min(size-1, size - n);
- s += s.substr(m ,size);
- x = stod(s);
- k = size - 2 - n;
- b = pow(10, k + n) ;
- if (n != 0)
- b -= pow(10, k);
- a = pow(10, k + n)*x;
- if(n!=0)
- a-= (int)(pow(10, k)*x);
- int g = gcd(a, b);
- printf("Case %d: ", css); ++css;
- printf("%d/%d\n", a/g,b/g);
- cin >> n;
- }
- system("pause");
- }
Add Comment
Please, Sign In to add comment