0
点赞
收藏
分享

微信扫一扫

C++数据结构——进制转换

瑾谋 2022-03-19 阅读 54
java后端

题目描述

输入格式:

输出格式:

输入样例:

输出样例:

解题代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int T;
	cin>>T;
	int n,k,num,m;
	list<int> link;
	while(T--){
		cin>>n>>k;
		m=fabs(n);
		while(m){
			num=m%k;
			link.push_front(num);
			m/=k;
		}
		cout<<n<<" ";
		list<int>::iterator iter;
		if(n<0)cout<<"-";
		else if(n==0) cout<<0;
		for(iter=link.begin();iter!=link.end();iter++){
			cout<<(*iter);
		}
		cout<<endl;
		link.clear();
	}
}

解题思路

举报

相关推荐

0 条评论