题目:

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. 【13】python time时间模块知识点备查

    表示时间的三种形式 # 时间模块 '''UTC(世界协调时间):格林尼治天文时间,世界标准时间,在中国来说是UTC+8DST(夏令时):是一种节约能源而人为规定时间制度,在夏季调快1个小时 时间的表示 ...

  2. php 错误1

    Maximum execution time of 30 seconds exceeded 方法一,修改php.ini文件 max_execution_time = 30; Maximum execu ...

  3. JS中的防抖与节流

    什么是防抖?and什么是节流?一起来开心的学习下吧. 首先什么是防抖:就是在一定的时间内事件只发生一次,比如你点击button按钮,1秒内任你单身30年手速点击无数次,他也还是只触发一次.举个例子,当 ...

  4. Spring IOC容器创建bean过程浅析

    1. 背景 Spring框架本身非常庞大,源码阅读可以从Spring IOC容器的实现开始一点点了解.然而即便是IOC容器,代码仍然是非常多,短时间内全部精读完并不现实 本文分析比较浅,而完整的IOC ...

  5. SDOI 2018 R2 游记

    一篇真正的“游记”. DAY -3 下午: 今天老师批准了我去省选划水的请假要求. 批准之后感觉学习非常有动力,顺便忽悠别的同学和我一起去,然而wzx是唯一一个表示可以考虑一下的同学,其他同学直接一口 ...

  6. 根据拼音首字母进行过滤的combobox

    keywords: 拼音 首字母 过滤 在combobox中输入汉字拼音的首字母时,下面列出对应的可选项,就像下面这样 1. 首先在数据库中需要设计一个表,专门用来存放药物及对应的拼音首字母,这样当用 ...

  7. 不要以为字段以transient修饰的话就一定不会被序列化

    1: 先阅读这边文章:http://www.importnew.com/21517.html 2:被transient修饰真的会被序列化吗? 反例:java.util.ArrayList中底层存储数组 ...

  8. centos6.5 64位静默安装oracle 10G R2

    操作系统:CentOS release 6.5 (Final) 64位 oracle版本:Oracle Database 10g Enterprise Edition Release 10.2.0.1 ...

  9. Zookeeper入门(三)之工作流

    一旦ZooKeeper集合启动,它将等待客户端连接.客户端将连接到ZooKeeper集合中的一个节点.它可以是leader或follower节点.一旦客户端被连接,节点将向特定客户端分配会话ID并向该 ...

  10. python面试一:python2与python3的区别一

    1.默认编码方式不同:py3用的是utf-8,变量名更为广泛.2.去除<>改用!=3加入as 和with关键字4./除法默认数据类型不同 py2 5/3=1 py3 5//3=15.去掉了 ...