Skip to content

E02734:十进制到八进制

http://cs101.openjudge.cn/practice/02734

思路:直接除8取余,个人感觉最快捷

cpp
#include <iostream>
#include <string>
using namespace std;

int main() {
    int a;
    cin >> a;  
    string octal;  
    while (a > 0) {
        int remainder = a % 8;  
        octal = to_string(remainder) + octal; 
        a = a / 8;  
    }

    cout << octal << endl;  
    return 0;
}