fork(1) download
  1. #include <iostream>
  2. #include <map>
  3. using namespace std;
  4.  
  5. int main() {
  6. int a = 1, b = 10;
  7. cout << "Rozwiniecie binarne 1/10:\n0.";
  8.  
  9. map<int,int> seen;
  10. string result = "";
  11. int pos = 0;
  12. int r = a;
  13.  
  14. while (true) {
  15. if (r == 0) {
  16. cout << result << endl;
  17. break;
  18. }
  19. if (seen.count(r)) {
  20. int start = seen[r];
  21. cout << result.substr(0,start) << "(" << result.substr(start) << ")" << endl;
  22. break;
  23. }
  24. seen[r] = pos++;
  25. r *= 2;
  26. if (r >= b) {
  27. result += '1';
  28. r -= b;
  29. } else {
  30. result += '0';
  31. }
  32. }
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Rozwiniecie binarne 1/10:
0.0(0011)