标签:style blog color os io for ar div log
2<=N,M<=36
输入为0~9 A~Z
输出0~9 a~z
X任意大小
#include<iostream> #include<string> #include<cmath> #include<algorithm> #include<stdio.h> using namespace std; int a[1000],s[1000]; int main() { int n,m,k,f; string x; while(scanf("%d%d",&m,&n)!=EOF) { int i,k=0; cin>>x; int l=x.length(); for(i=0;i<l;i++) { if(x[i]>=‘0‘ && x[i]<=‘9‘) s[i]=x[i]-‘0‘; else s[i]=x[i]-‘A‘+10; } while(1) { for(i=0;i<l-1;i++) { s[i+1]+=s[i]%n*m; s[i]/=n; } a[k]=s[l-1]%n; s[l-1]/=n; k++; f=0; for(i=0;i<l;i++) { if(s[i]>0) f=1; } if(!f) break; } for(i=k-1;i>=0;i--) { if(a[i]<10) cout<<char(a[i]+‘0‘); else cout<<char(a[i]+‘a‘-10); } cout<<endl; } }
标签:style blog color os io for ar div log
原文地址:http://www.cnblogs.com/rongxxx/p/3934950.html