题目链接:https://leetcode.com/problems/base-7/#/description
Given an integer, return its base 7 string representation.
Example 1:
Input: 100 Output: "202"
Example 2:
Input: -7 Output: "-10"
class Solution {
public:
string convertToBase7(int num) {
if(num==0)
return "0";
int number=abs(num);
string res="";
while(number)
{
int n=number%7;
res=to_string(n)+res;
number/=7;
}
if(num<0)
res="-"+res;
return res;
}
};