fork(2) download
  1. #define ANSI
  2.  
  3. #include <iostream>
  4. #include <cstring>
  5. #include <bitset>
  6. #include <climits>
  7. #include <sstream>
  8.  
  9. using namespace std;
  10.  
  11. void printfloat(float);
  12.  
  13. int main()
  14. {
  15. int t;
  16. float x;
  17. cin >> t; /* wczytaj liczbę testów */
  18. while(t)
  19. {
  20. cin >> x;
  21. printfloat(x);
  22. t--;
  23. }
  24. return 0;
  25. } /* ........................ Tu napisz potrzebne funkcje */
  26.  
  27. void printfloat(float valu)
  28. {
  29. if(valu != 0.0f)
  30. {
  31. union {
  32. float a;
  33. int out;
  34. }data;
  35. data.a = valu;
  36.  
  37. bitset<sizeof(float) * CHAR_BIT> floatBits(data.out);
  38.  
  39.  
  40. string str = floatBits.to_string();
  41.  
  42. int len = str.length();
  43. int j = 1;
  44. bool was = false;
  45. for(int i =0;i < len;i+=4)
  46. {
  47. string s;
  48. s += str[i];
  49. s += str[i + 1];
  50. s += str[i + 2];
  51. s += str[i + 3];
  52.  
  53. if (s == "0000" && (!was))
  54. {
  55. cout << "0";
  56. was = true;
  57. }
  58. if (s == "0001")
  59. cout << "1";
  60. if (s == "0010")
  61. cout << "2";
  62. if (s == "0011")
  63. cout << "3";
  64. if (s == "0100")
  65. cout << "4";
  66. if (s == "0101")
  67. cout << "5";
  68. if (s == "0110")
  69. cout << "6";
  70. if (s == "0111")
  71. cout << "7";
  72. if (s == "1000")
  73. cout << "8";
  74. if (s == "1001")
  75. cout << "9";
  76. if (s == "1010")
  77. cout << "a";
  78. if (s == "1011")
  79. cout << "b";
  80. if (s == "1100")
  81. cout << "c";
  82. if (s == "1101")
  83. cout << "d";
  84. if (s == "1110")
  85. cout << "e";
  86. if (s == "1111")
  87. cout << "f";
  88.  
  89. if (j % 2 == 0)
  90. {
  91. cout << " ";
  92. was = false;
  93. }
  94. j++;
  95. }
  96.  
  97. }else
  98. {
  99. cout << "0 0 0 0" ;
  100. }
  101. cout << endl;
  102. }
Success #stdin #stdout 0s 3464KB
stdin
5
1
-1
0
123.125
-345
stdout
3f 80 0 0 
bf 80 0 0 
0 0 0 0
42 f6 40 0 
c3 ac 80 0