首页 > 试题广场 >

八进制

[编程题]八进制
  • 热度指数:31098 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
输入一个整数,将其转换成八进制数输出。

输入描述:
输入包括一个整数N(0<=N<=100000)。


输出描述:
可能有多组测试数据,对于每组数据,
输出N的八进制表示数。
示例1

输入

7
8
9

输出

7
10
11
while True:
    try:
        a = int(input())
        b = oct(10)
        print(format(eval(b),'o'))
    except:
        break

发表于 2020-12-06 22:12:09 回复(0)
while True:
    try:
        n=int(input().strip())
        print(oct(n).lstrip('0o'))
    except:
        break
发表于 2019-08-26 10:57:36 回复(0)
print(oct(int(input())).replace("0o",""))
One Line Solution
发表于 2018-07-05 02:04:22 回复(0)

python3 solution,only one line

note: use oct() function, and you should cut the "0o" in the begin position using replace() function.

while True:
    try:
        print(oct(int(input())).replace("0o",""))

    except:
        break
编辑于 2018-04-18 08:02:47 回复(3)
def change(n):
    if n<8:
        return n
    s=''
    while n:
        y=n%8
        s=str(y)+s
        n=int(n/8)
    return s
        
try:
    while True:
        n=int(input())
        if not n:
            break
        print(change(n))
        
except:
    pass


发表于 2017-07-02 17:53:07 回复(0)
import sys
while True:
line = sys.stdin.readline().strip()
if line == '':
break
else:
i = int(line)
if i == 0:
print 0
else:
j = 0
k = []
while i:
f = i % 8
i = i / 8
k.append(f)
j += 1
s = ''
for i in k[::-1]:
s+=str(i)
print s

同一份代码 既能编译错误 也能通过 无***说
还有我写的是return 一直给我报错数组越界 最后改成print才好 真真棒棒
编辑于 2017-03-11 21:54:54 回复(0)
try:
    while 1:
        print oct(input())[1:]
except:
    pass

发表于 2016-12-23 02:02:22 回复(0)

问题信息

难度:
7条回答 16666浏览

热门推荐

通过挑战的用户

查看代码