진법 변환 2

BiBi·2021년 1월 19일
0

코딩테스트연습

목록 보기
44/66
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <cmath>
using namespace std;



int main() {
	//freopen("input.txt", "rt", stdin);
	long long n;
	long long b;
	cin >> n >> b;
	stack<long long> s;

	while (n>0) {
		long long tmp = n % b;
		s.push(tmp);
		n = n / b;
	}
	int num = s.size();
	for (int i = 0; i < num; i++) {
		if (s.top() >= 10) {
			printf("%c", s.top() + 'A' - 10);
		}
		else {
			cout << s.top();
		}
		s.pop();
	}


	return 0;
}
profile
Server Network Engineer

0개의 댓글