题目:

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. January 01st, 2018 Week 01st Monday

    Life's like a movie, write your own. Keep believing, keep pretending. 人生如同电影,书写自己的结局.持续相信,继续演出. Some ...

  2. [ML学习笔记] 朴素贝叶斯算法(Naive Bayesian)

    [ML学习笔记] 朴素贝叶斯算法(Naive Bayesian) 贝叶斯公式 \[P(A\mid B) = \frac{P(B\mid A)P(A)}{P(B)}\] 我们把P(A)称为"先 ...

  3. 张高兴的 .NET Core IoT 入门指南:(一)环境配置、Blink、部署

    如何在 Raspberry Pi 的 Raspbian 上构建使用 GPIO 引脚的 IoT 程序?你可能会回答使用 C++ 或 Python 去访问 Raspberry Pi 的引脚.现在,C# 程 ...

  4. facebook api & oauth protocal

    http://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-10.5 http://stackoverflow.com/questions/14 ...

  5. Tomcat设置虚拟目录的方法, 不修改server.xm

    所在小组使用的就是这样的形式开发,这样切换开发环境,测试环境,正式环境就只需要修改project.xml文件就行了.project.xml命名是随意的,访问的时候就使用这个名字来访问. 在tomcat ...

  6. BZOJ2460:[BJWC2011]元素(贪心,线性基)

    Description 相传,在远古时期,位于西方大陆的 Magic Land 上,人们已经掌握了用魔法矿石炼制法杖的技术.那时人们就认识到,一个法杖的法力取决于使用的矿石. 一般地,矿石越多则法力越 ...

  7. Java应用中的编码问题(转载)

    第三篇:JAVA字符编码系列三:Java应用中的编码问题这部分采用重用机制,引用一篇文章来完整本部分目标.来源:  Eceel东西在线 问题研究--字符集编码 地址:http://china.ecee ...

  8. leetcode349—Intersection of Two Arrays

    Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1 ...

  9. 蓝桥杯之剪格子(经典dfs)

    如下图所示,3 x 3 的格子中填写了一些整数. +--*--+--+ |10* 1|52| +--****--+ |20|30* 1| *******--+ | 1| 2| 3| +--+--+-- ...

  10. Unable to start a VM due to insufficient capacity

    今天cloudstack中的一个普通用户创建虚拟机时,总是报错:Unable to start a VM due to insufficient capacity ,看management and a ...