fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. unsigned long long GCD (unsigned long long a, unsigned long long b) {
  6. if (b == 0) return a;
  7. else return GCD (b, a % b);
  8. }
  9.  
  10. int main() {
  11. char str[20];
  12. int length = 0;
  13. while (cin >> str[length]) length++;
  14. unsigned long long numerator = 0, denominator = 1, gcd, fraction, remainder;
  15. for (int i = 0; i < length; i++) {
  16. if(str[i] != '.') numerator = numerator * 10 + (str[i] - '0');
  17. }
  18. while (--length > 1) denominator *= 10;
  19. gcd = GCD(numerator, denominator);
  20. numerator /= gcd;
  21. denominator /= gcd;
  22. remainder = numerator % denominator;
  23. numerator -= remainder;
  24. fraction = numerator / denominator;
  25. cout << denominator << endl;
  26. for (int i = 1; i <= 5; i++) {
  27. if(i == fraction) {
  28. i++;
  29. cout << denominator - remainder << " ";
  30. if(fraction != 5) cout << remainder << " ";
  31. }
  32. else cout << 0 << " ";
  33. }
  34. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
1
0 0 0 0 0