题目:

Given an integer, return its base 7 string representation.

Example 1:

Input: 100
Output: "202"

Example 2:

Input: -7
Output: "-10"

Note: The input will be in range of [-1e7, 1e7].

分析:

给定一个7进制数,求十进制表示,注意返回的是字符串。

进制转换没什么好说的,注意这道题测试用例是有负数的,且返回值是字符串,记得转成字符串形式。

程序:

class Solution {
public:
string convertToBase7(int num) {
if(num == ) return "";
string res;
int n = abs(num);
while(n){
res = to_string(n%) + res;
n /= ;
}
if(num < )
return "-"+res;
else
return res;
}
};

LeetCode 504. Base 7 (C++)的更多相关文章

  1. 45. leetcode 504. Base 7

    504. Base 7 Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: ...

  2. [LeetCode] 504. Base 7 基数七

    Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202&q ...

  3. [LeetCode] 504. Base 7_Easy tag: Math

    Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202&q ...

  4. C#版 - Leetcode 504. 七进制数 - 题解

    C#版 - Leetcode 504. 七进制数 - 题解 Leetcode 504. Base 7 在线提交: https://leetcode.com/problems/base-7/ 题目描述 ...

  5. 【leetcode】504. Base 7

    problem 504. Base 7 solution: class Solution { public: string convertToBase7(int num) { ) "; st ...

  6. 【LeetCode】504. Base 7 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 内建库 BigInteger类 逐位计算 倍数相加 ...

  7. [LeetCode&Python] Problem 504. Base 7

    Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202&q ...

  8. 504. Base 7

    Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202&q ...

  9. 504 Base 7 七进制数

    给定一个整数,将其转化为7进制,并以字符串形式输出.示例 1:输入: 100输出: "202" 示例 2:输入: -7输出: "-10"注意: 输入范围是 [- ...

随机推荐

  1. [BZOJ 1135][POI2009]Lyz

    [BZOJ 1135][POI2009]Lyz 题意 初始时滑冰俱乐部有 \(1\) 到 \(n\) 号的溜冰鞋各 \(k\) 双.已知 \(x\) 号脚的人可以穿 \(x\) 到 \(x+d\) 的 ...

  2. DevExpress12、DocumentManager

    DocumentManager控件 你用过Photoshop吗?里面每打开一个照片,就有一个小窗体承载这个照片,你可以在这些小窗体间切换,最小化.最大化.排列窗体, 这些操作都在Photoshop的大 ...

  3. 团队作业7——第二次项目冲刺(Beta版本)day2

    项目成员:  曾海明(组长):201421122036 于波(组员):201421122058 蓝朝浩(组员):201421122048 王珏 (组员):201421122057 叶赐红(组员):20 ...

  4. Terminal Service 终端链接

    2008 64位前有这项服务,之后就与远程管理合并了 如果要设置他的连接数可以去 桌面 --> 管理工具 --> 远程桌面服务 最大数设置成1个好了

  5. vultr vps(ubuntu)忘记密码

    参考官方解决方案:https://www.vultr.com/docs/boot-into-single-user-mode-reset-root-password 在此仅给出ubuntu下的解决 D ...

  6. http-server

    http-server是基于node.js的一个简单.零配置的命令行web服务器,可以方便实现跨域资源请求, #全局安装: npm install http-server -g: 全局安装后就可以通过 ...

  7. 6.Solr4.10.3API使用(CURD)

    转载请出自出处:http://www.cnblogs.com/hd3013779515/ 1.在工程中引入solr-solrj-4.10.3.jar <dependency> <gr ...

  8. Github进行fork后如何与原仓库同步

    https://blog.csdn.net/myuantao3286286/article/details/50477139

  9. 【转】Fiddler工作原理

    原文章链接:Web代码网chinabit.org Fiddler是一个http调试代理,它能 够记录所有的你电脑和互联网之间的http通讯,Fiddler 可以也可以让你检查所有的http通讯,设置断 ...

  10. Sqoop学习之路 (一)

    一.概述 sqoop 是 apache 旗下一款“Hadoop 和关系数据库服务器之间传送数据”的工具. 核心的功能有两个: 导入.迁入 导出.迁出 导入数据:MySQL,Oracle 导入数据到 H ...