标签:
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
#include<cstdio> #include<cstring> using namespace std; int main() { int n,i,x,y,l,k,t[100],b[100]; char s[100],ans[100];//由于超过十进制的数含有字母,因此用字符串数组储存 for (scanf("%d",&n);n--;) { scanf("%d%d%s",&x,&y,s); for (i=k=strlen(s);0<i--;) t[k-1-i]=s[i]-(s[i]<58?48:s[i]<97?55:61);//ascall码48到57为字符0到一,97到122对应小写字母a到b,将字符转变成相应的十进制数存入数组t中。 for (l=0;k;) { for (i=k;1<i--;) //这一坨for循环我实在搞不懂啥意思 { t[i-1]+=t[i]%y*x; t[i]/=y;//貌似是使除t[0]以外的变为y进制 } b[l++]=t[0]%y;//由于t[0]是最低位,相当于将t[0]作为一个独立的单位进行处理。 t[0]/=y; for (;0<k&&!t[k-1];k--);//当t最高位为0时,缩短t的长度。 } for (ans[l]=i=0;i<l;i++) ans[l-1-i]=b[i]+(b[i]<10?48:b[i]<36?55:61); printf("%d %s\n%d %s\n\n",x,s,y,ans); } return 0;
标签:
原文地址:http://www.cnblogs.com/sjymj/p/5189528.html