int main()
{
int t;
cin >> t;
while (t–){
ll m;
int n;
cin >> m >> n;
if (m < 0){
cout << “-“;
m = -m;
}
int a[100];
int k = 0;
while (m){
a[k] = m%n;
m = m / n;
k++;
}
for (int i = k-1; i >= 0; i–){
if (a[i] >= 0 && a[i] <= 9) cout << a[i];
else {
char r = a[i] - 10 + ‘A’;
cout << r;
}
}
cout << endl;
}
return 0;
}
注意32位啊,
比较简短的代码 命名有点不规范!
include
using namespace std;
typedef long long ll;
int main()
{
int t;
cin >> t;
while (t–){
ll m;
int n;
cin >> m >> n;
if (m < 0){
cout << “-“;
m = -m;
}
int a[100];
int k = 0;
while (m){
a[k] = m%n;
m = m / n;
k++;
}
for (int i = k-1; i >= 0; i–){
if (a[i] >= 0 && a[i] <= 9) cout << a[i];
else {
char r = a[i] - 10 + ‘A’;
cout << r;
}
}
cout << endl;
}
return 0;
}
include
void binary(int, int);
int main()
{
int t;scanf(“%d”,&t);
while(t–){
int N, R;
while(scanf(“%d %d”, &N, &R)!=EOF)
{
if(N==0)
printf(“%d”,0);
else if(N<0)
{
printf(“-“);
N=-N;}
binary(N, R);
printf(“\n”);
}}
return 0;
}
void binary(int n, int r)
{
int m;
if(n==0)
return;
else
{
binary(n/r, r);
m=n%r;
if(m<10)
printf(“%d”, m);
else
printf(“%c”, ‘A’+m-10);
}
}
注意处理符号
我该肿么办?!
32位
include
include
include
include
define N 50
char array[N]=”\0”;
int Ten_LessThanTen(int after, int num) //10转换10以内,参数after为转换后的进制,num为10进制数值
{ if(num<0){num=-num;
char array[N]=”\0”;
char result[N]=”\0”;
}}char * Ten_MoreThanTen(int after, int num) //10转换10以上
{
}
int main()
{
int cs;
scanf(“%d”,&cs);
int i;
for(i=0;i<cs;i++)
{ long long int n,R;
}
}
注意特判0(虽然不知道测试数据里有没有0)
这题有bug,没有特判0
纠结~~,这为啥过不了啊。。
flag哪里错了啊,楼主
纠结~~,这为啥过不了啊。。
你16年问11年肯定不行啊。。。