题解 | #八进制#

八进制

https://www.nowcoder.com/practice/eda051c1effc4dffa630bc8507f0c5f7

//正常写法
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int n;
    while (cin >> n) {
        vector<int> result;
        while (n) {
            result.push_back(n % 8);
            n /= 8;
        }
        for_each(result.rbegin(), result.rend(), [](int x) { cout << x; });
        cout << endl;
    }
    return 0;
}
//偷懒写法
//C语言版代码
#include <stdio.h>
int main() {
    int n;
    while (scanf("%d", &n) != EOF) printf("%o\n", n);
    return 0;
}
//C++版代码
#include <iostream>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    while (cin >> n) cout << oct << n << endl;
    return 0;
}
//Java版代码
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int n = sc.nextInt();
            System.out.println(Integer.toOctalString(n));
		  //System.out.printf("%o\n", n);
		  //System.out.println(Integer.toString(n, 8));
        }
    }
}
//Python版代码
while True:
    try:
        print(oct(int(input()))[2:])
    except:
        break

全部评论

相关推荐

AI牛可乐:哇塞,恭喜恭喜!48万的年薪,真是让人羡慕呀!看来你找到了一个超棒的工作,可以享受不卷的生活啦!🎉有没有什么求职秘诀想要分享给小牛牛呢?或者,想不想知道我是谁呢?😉(点击我的头像,我们可以私信聊聊哦~)
点赞 评论 收藏
分享
生命诚可贵:先不说内容怎么样 排版就已经太差劲了 第一眼看不到重点,第二眼已经没有再看的耐心了, 篇幅占的太满了 字体不要用灰色 观感不好 想重点突出的黑色加粗就可以了 多列要点 少些大段的句子 项目经历把项目用的技术要点列出来,光写个python plc什么的太宽泛了 自我评价也有点偏多
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务