1
0

DivConvert.h 540 B

1234567891011121314151617181920212223242526272829
  1. //
  2. // Created by 李洋 on 2023/10/2.
  3. //
  4. #ifndef LEECODE_C_DIVCONVERT_H
  5. #define LEECODE_C_DIVCONVERT_H
  6. #include <stack>
  7. #include <string>
  8. using namespace std;
  9. string decimalToBinaryUsingEuclidean(int target) {
  10. stack<int> s;
  11. string result = "";
  12. while (target) {
  13. s.push(target % 2);
  14. target /= 2;
  15. }
  16. while (!s.empty()) {
  17. result.append(to_string(s.top()));
  18. s.pop();
  19. }
  20. return result;
  21. }
  22. // test : cout << decimalToBinaryUsingEuclidean(555) << endl;
  23. #endif //LEECODE_C_DIVCONVERT_H
备用站点 当前处于降级运行的备用站点,仅供应急访问,数据和功能可能不是最新。