Huazhong University of Science and Technology test machine octal Easy

The basic idea:

no;

 

key point:

no;

 

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

void charge(int n) {
	string res = "";
	if (n == 0) {
		cout << 0 << endl;
		return;
	}
	while (n != 0) {
		res = char('0' + n % 8) + res;
		n /= 8;
	}
	cout << res << endl;
}

int main() {
	int n;
	while (cin >> n) {
		charge(n);
	}
}

  

Guess you like

Origin www.cnblogs.com/songlinxuan/p/12460038.html