fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdint>
  4.  
  5. class CastSpells{
  6. std::string Words;
  7.  
  8. public:
  9. CastSpells(char* str) :Words(str){}
  10.  
  11. CastSpells& operator ()(){
  12. std::cout << Words << std::endl;
  13. return *this;
  14. }
  15. };
  16. typedef std::pair<std::uint16_t, std::uint16_t> Pair16;
  17. Pair16 FullAdder(std::uint16_t A, std::uint16_t B, std::uint16_t C){//ここからパクった。良いページだ。ttp://www.mech.tohoku-gakuin.ac.jp/rde/contents/course/mechatronics/digital.html
  18.  
  19. int S1 = A ^ B;
  20. int C1 = A & B;
  21. int S = S1 ^ C;
  22. int C2 = S1 & C;
  23. int Co = C1 | C2;
  24.  
  25. return std::make_pair(S,Co);
  26. }
  27.  
  28. std::uint16_t AddOne(std::uint16_t N){
  29. int i = 0;
  30. int B = 1;
  31. int R = 0;
  32. Pair16 Pa;
  33. //0
  34. Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
  35. R |= Pa.first;
  36. i=1;
  37. //1
  38. Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
  39. R |= Pa.first;
  40. i=2;
  41. //2
  42. Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
  43. R |= Pa.first;
  44. i=3;
  45. //3
  46. Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
  47. R |= Pa.first;
  48. i=4;
  49. //4
  50. Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
  51. R |= Pa.first;
  52. i=5;
  53. //5
  54. Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
  55. R |= Pa.first;
  56. i=6;
  57. //6
  58. Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
  59. R |= Pa.first;
  60. i=7;
  61. //7
  62. Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
  63. R |= Pa.first;
  64. i=8;
  65. //8
  66. Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
  67. R |= Pa.first;
  68. i=9;
  69. //9
  70. Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
  71. R |= Pa.first;
  72. i=10;
  73. //10
  74. Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
  75. R |= Pa.first;
  76. i=11;
  77. //11
  78. Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
  79. R |= Pa.first;
  80. i=12;
  81. //12
  82. Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
  83. R |= Pa.first;
  84. i=13;
  85. //13
  86. Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
  87. R |= Pa.first;
  88. i=14;
  89. //114
  90. Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
  91. R |= Pa.first;
  92. i=15;
  93. //15
  94. Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
  95. R |= Pa.first;
  96. i=0;
  97. return R;
  98. }
  99.  
  100. int main(){
  101. CastSpells CS("Hello World!!");
  102. CS()()()()()()()();//おまけ!
  103. std::cout << "---------------" <<std::endl ;
  104. int N = 8;
  105.  
  106. for (int i = 0; i < 65535; i++){
  107. if (i + 1 != AddOne(i)){
  108. std::cout << "this logic is broken!";
  109. return -1;
  110. }
  111. }
  112. std::cout << "Logic test Passed!" <<std::endl ;
  113.  
  114. for (int i = 0; i < N; i = AddOne(i)){
  115. std::cout << "Hello World!" << std::endl;
  116. }
  117.  
  118. return 0;
  119. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
Hello World!!
Hello World!!
Hello World!!
Hello World!!
Hello World!!
Hello World!!
Hello World!!
Hello World!!
---------------
Logic test Passed!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!