标签:c++ poj numbers iostream 编程
poj 50题拍照合影留念
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 4620 | Accepted: 2115 |
Description
Input
Output
Sample Input
8 62 2 abcdefghiz 10 16 1234567890123456789012345678901234567890 16 35 3A0C92075C0DBF3B8ACBC5F96CE3F0AD2 35 23 333YMHOUE8JPLT7OX6K9FYCQ8A 23 49 946B9AA02MI37E3D3MMJ4G7BL2F05 49 61 1VbDkSIMJL3JjRgAdlUfcaWj 61 5 dl9MDSWqwHjDnToKcsWE1S 5 10 42104444441001414401221302402201233340311104212022133030
Sample Output
62 abcdefghiz 2 11011100000100010111110010010110011111001001100011010010001 10 1234567890123456789012345678901234567890 16 3A0C92075C0DBF3B8ACBC5F96CE3F0AD2 16 3A0C92075C0DBF3B8ACBC5F96CE3F0AD2 35 333YMHOUE8JPLT7OX6K9FYCQ8A 35 333YMHOUE8JPLT7OX6K9FYCQ8A 23 946B9AA02MI37E3D3MMJ4G7BL2F05 23 946B9AA02MI37E3D3MMJ4G7BL2F05 49 1VbDkSIMJL3JjRgAdlUfcaWj 49 1VbDkSIMJL3JjRgAdlUfcaWj 61 dl9MDSWqwHjDnToKcsWE1S 61 dl9MDSWqwHjDnToKcsWE1S 5 42104444441001414401221302402201233340311104212022133030 5 42104444441001414401221302402201233340311104212022133030 10 1234567890123456789012345678901234567890
Source
任意进制的转换AC
#include <iostream> #include <cstring> #include <cstdio> #define maxn 999 int aa[maxn],bb[maxn]; char a[maxn],b[maxn]; using namespace std; int main(){ int loop,ibase,obase,i,count,len,j; cin>>loop; while(loop--){ scanf("%d %d %s",&ibase,&obase,a); len=strlen(a); for(i=len-1,j=0;i>=0;--i) aa[j++]=a[i]-(a[i]<='9'?48:a[i]<'a'?55:61); count=0; while(len>0){ j=len-1; while(j){ aa[j-1]+=aa[j]%obase*ibase; aa[j]/=obase; j--; } bb[count++]=aa[0]%obase; aa[0]/=obase; while(0<len&&!aa[len-1])len--; } ///printf("count=%d\n",count); for(b[count]='\0',i=count-1,j=0;i>=0;i--,j++) b[j]=bb[i]+(bb[i]<10?48:bb[i]<36?55:61); printf("%d %s\n%d %s\n\n",ibase,a,obase,b); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 1220 NUMBER BASE CONVERSION 高精度进制转换
标签:c++ poj numbers iostream 编程
原文地址:http://blog.csdn.net/zp___waj/article/details/47703677