504. Base 7
来源:互联网 发布:海康监控软件 编辑:程序博客网 时间:2024/06/15 14:36
题目:
Given an integer, return its base 7 string representation.
Example 1:
Input: 100Output: "202"
Example 2:
Input: -7Output: "-10"
Note: The input will be in range of [-1e7, 1e7].
思路:本题主要考查的是进制的转换
代码:
class Solution {public: string convertToBase7(int num) { string str; if(num==0) return "0"; if(num>0){ while(num){ str +=to_string(num%7); cout<<str<<endl; num = num / 7; } reverse(str.begin(),str.end()); } else{ num = abs(num); while(num){ str +=to_string(num%7); cout<<str<<endl; num = num / 7; } str += "-"; reverse(str.begin(),str.end()); } return str; }};
阅读全文
1 0
- Leetcode-504. Base 7
- 【Leetcode】504. Base 7
- LeetCode 504. Base 7
- 504. Base 7
- [leetcode]504. Base 7
- 504. Base 7
- 504. Base 7
- 504. Base 7
- 504. Base 7
- LeetCode-504. Base 7
- 504. Base 7
- 504. Base 7
- 504. Base 7
- leetcode 504. Base 7
- 504. Base 7
- LeetCode:504. Base 7
- [LeetCode]504. Base 7
- leetcode 504. Base 7
- D3.js学习笔记十五:D3.js树图(Tree)展开和折叠
- 二进制 与十进制 互相转换
- 国家代码
- 测试代码运行后不报错,数据库也会生成表,但控制台不能输出。哪位大神能帮我解决?
- composer 安装yii2框架
- 504. Base 7
- 关于ASP.NET 发送电子邮件
- 原型模式
- 剑指offer——反转链表
- autolayout异常解决
- cURL请求接口出现name lookup timed out
- JVM内存分几种?
- Fibonacci 快速幂矩阵
- 安卓获取系统当前时间