美文网首页
Day5 EP-504 Base 7

Day5 EP-504 Base 7

作者: 李庆文 | 来源:发表于2018-02-02 23:26 被阅读11次

一.问题描述

问题描述

二.问题解决

class Solution {
public:
    string convertToBase7(int num) {
        
        bool is_negative = num<0?true:false;
        
        string ans = "";
        
        num=abs(num);  
        
        while(num > 0){
            ans = to_string(num%7) + ans;
            num = num/7;
        }
        
        if(is_negative){
            ans="-"+ans;
        }
        if(ans==""){
            ans = "0";
        }
       return ans;
    }
};

进制转换问题,经典的取余,整除方法。
继续加油啦。

相关文章

  • Day5 EP-504 Base 7

    一.问题描述 二.问题解决 进制转换问题,经典的取余,整除方法。继续加油啦。

  • 504. Base 7

    Given an integer, return its base 7 string representation...

  • Base64编码简单总结

    1 Base64编码原理 随着iOS7正式版推出,Apple增加了使用Base64编解码的支持。Base64编码之...

  • [LeetCode]504. Base 7

    题目 Given an integer, return its base 7 string representat...

  • [LeetCode By Go 56]504. Base 7

    题目 Given an integer, return its base 7 string representat...

  • base64

    s =b'i\xb7\x1d\xfb\xef\xff=='"""标准base64"""s_en = base64....

  • 攻防世界-Crypto-告诉你个秘密

    题目信息 得到两串base64 解密base64,得到7段字符,疑似键盘围绕加密 解密得到:TONGYUAN(必须...

  • menuconfig之编译选项2

    7>. Boot options (0x0) Compressed ROM boot loader base ...

  • 504. Base 7

    求一个数的7进制表示。这题跟Excel Sheet有点像。这类题可以用递归。 我的代码: 别人的代码: 用了递归

  • 18.Base 7

网友评论

      本文标题:Day5 EP-504 Base 7

      本文链接:https://www.haomeiwen.com/subject/lxnjzxtx.html