进制转换专属坑位!!!(x进制转y进制最终定型版)

#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
int ntoten(int x,string y)//x-10
{
	char a[105];
	int sum=0;
	y.copy(a,y.size(),0);
	a[strlen(a)]='\0';
	int c=strlen(a)-1;
	for(int i=0;i<=c;i++){
		sum+=(a[i]-'0')*pow(x,c-i);
	}
	return sum;
}
void tenton(int n, int t) {//10-y
	int i=0, k, num[100];
	while (n != 0) {
		num[i] = n % t;
		n = n / t;
		i++;
	}
	for (k = i-1; k >= 0; k--) {
		switch (num[k]) {
		case 0:
			cout << "0"; break;
		case 1:
			cout << "1"; break;
		case 2:
			cout << "2"; break;
		case 3:
			cout << "3"; break;
		case 4:
			cout << "4"; break;
		case 5:
			cout << "5"; break;
		case 6:
			cout << "6"; break;
		case 7:
			cout << "7"; break;
		case 8:
			cout << "8"; break;
		case 9:
			cout << "9"; break;
		case 10:
			cout << "A"; break;
		case 11:
			cout << "B"; break;
		case 12:
			cout << "C"; break;
		case 13:
			cout << "D"; break;
		case 14:
			cout << "E"; break;
		case 15:
			cout << "F"; break;
		case 16:
			cout << "G"; break;
		case 17:
			cout << "H"; break;
		case 18:
			cout << "I"; break;
		case 19:
			cout << "J"; break;
		case 20:
			cout << "K"; break;
		case 21:
			cout << "L"; break;
		case 22:
			cout << "M"; break;
		case 23:
			cout << "N"; break;
		case 24:
			cout << "O"; break;
		case 25:
			cout << "P"; break;
		case 26:
			cout << "Q"; break;
		case 27:
			cout << "R"; break;
		case 28:
			cout << "S"; break;
		case 29:
			cout << "T"; break;
		case 30:
			cout << "U"; break;
		case 31:
			cout << "V"; break;
		case 32:
			cout << "W"; break;
		case 33:
			cout << "X"; break;
		case 34:
			cout << "Y"; break;
		case 35:
			cout << "Z"; break;
		}
	}
}
int main()
{
	int jinzhi;
	string shuzi;
	int jinzhi2;
	cout<<"请输入待转换的进制(一个数字,如二进制就写2):";
	cin>>jinzhi;
	cout<<endl;
	cout<<"请输入带转换的数(一个数字):";
	cin>>shuzi;
	cout<<endl;
	cout<<"请输入需要转换成数的进制(一个数字如二进制就写2):"; 
	cin>>jinzhi2;
	int b=ntoten(jinzhi,shuzi);//b就是n转10的数
	cout<<endl;
	cout<<"转换中请稍后……";
	Sleep(2000);
	cout<<"转换成功,转换出的数是:"; 
	tenton(b,jinzhi2);//输出 
	return 0;
}
3 个赞

制作不易!!!点个赞吧!!!球求拉 :rofl:

2 个赞
#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
int ntoten(int x,string y)//x-10
{
	char a[105];
	int sum=0;
	y.copy(a,y.size(),0);
	a[strlen(a)]='\0';
	int c=strlen(a)-1;
	for(int i=0;i<=c;i++){
		sum+=(a[i]-'0')*pow(x,c-i);
	}
	return sum;
}
void tenton(int n, int t) {//10-y
	int i=0, k, num[100];
	while (n != 0) {
		num[i] = n % t;
		n = n / t;
		i++;
	}
	for (k = i-1; k >= 0; k--) {
		switch (num[k]) {
		case 0:
			cout << "0"; break;
		case 1:
			cout << "1"; break;
		case 2:
			cout << "2"; break;
		case 3:
			cout << "3"; break;
		case 4:
			cout << "4"; break;
		case 5:
			cout << "5"; break;
		case 6:
			cout << "6"; break;
		case 7:
			cout << "7"; break;
		case 8:
			cout << "8"; break;
		case 9:
			cout << "9"; break;
		case 10:
			cout << "A"; break;
		case 11:
			cout << "B"; break;
		case 12:
			cout << "C"; break;
		case 13:
			cout << "D"; break;
		case 14:
			cout << "E"; break;
		case 15:
			cout << "F"; break;
		case 16:
			cout << "G"; break;
		case 17:
			cout << "H"; break;
		case 18:
			cout << "I"; break;
		case 19:
			cout << "J"; break;
		case 20:
			cout << "K"; break;
		case 21:
			cout << "L"; break;
		case 22:
			cout << "M"; break;
		case 23:
			cout << "N"; break;
		case 24:
			cout << "O"; break;
		case 25:
			cout << "P"; break;
		case 26:
			cout << "Q"; break;
		case 27:
			cout << "R"; break;
		case 28:
			cout << "S"; break;
		case 29:
			cout << "T"; break;
		case 30:
			cout << "U"; break;
		case 31:
			cout << "V"; break;
		case 32:
			cout << "W"; break;
		case 33:
			cout << "X"; break;
		case 34:
			cout << "Y"; break;
		case 35:
			cout << "Z"; break;
		}
	}
}
int main()
{
	int jinzhi;
	string shuzi;
	int jinzhi2;
	cout<<"请输入待转换的进制(一个数字,如二进制就写2):";
	cin>>jinzhi;
	cout<<endl;
	cout<<"请输入带转换的数(一个数字):";
	cin>>shuzi;
	cout<<endl;
	cout<<"请输入需要转换成数的进制(一个数字如二进制就写2):"; 
	cin>>jinzhi2;
	int b=ntoten(jinzhi,shuzi);//b就是n转10的数
	cout<<endl;
	cout<<"转换中请稍后……";
	Sleep(2000);
	cout<<"转换成功,转换出的数是:"; 
	tenton(b,jinzhi2);//输出 
	cout<<"制作不易!点个赞吧!!!";
	return 0;
}
3 个赞

点赞支持
虽然不知道为什么这么简单还要这么多代码

3 个赞

已回赞

3 个赞

发博客里了

3 个赞

私聊 不然水贴

3 个赞

叫x进制转y进制(最终定型版)

2 个赞

别啊!!!

2 个赞

作者突然发现一个漏洞!!!不能输入字母啊!!!

1 个赞

你真的6

1 个赞