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