#include <stdio.h> #define N 1000 int Fun(char c){ if (c>='0'&&c<='9') { return c-'0'; } else { return c-'A'+10; } } int main(){ int m, n, k = 0; char a[N]; char b[N]; char c[] = "0123456789abcdefghijklmnopqrstuvwxyz"; long long sum = 0; scanf("%d%d", &m, &n); scanf("%s", a); for (int i = 0; a[i]!='\0'; i ++) { sum *= m; sum += Fun(a[i]); } while (sum) { b[k++] = c[sum%n]; sum /= n; } for (int i = k-1; i >= 0; i --) { printf("%c", b[i]); } return 0;
#include <stdio.h> #include <stdlib.h> #include <math.h> char str[1000]; //字符转数字 int chartoint(char c){ if(c>='0'&&c<='9'){ return c-'0'; }else{ return c-'A'+10; } } //数字转字符 char inttochar(int x){ if(x<10){ return x+'0'; }else{ return x-10+'A'; } } void change(int x,int y){ int len=strlen(str),k=0; char ans[100]={'0'}; for(int i=0,m=0;i<len;m++){ k=0; for(int j=i;j<len;j++){ int cur=k*x+chartoint(str[j]); k=cur%y; str[j]=inttochar(cur/y); } ans[m]=inttochar(k); while(str[i]=='0') i++; } for(int i=strlen(ans)-1;i>=0;i--){ printf("%c",ans[i]); } printf("\n"); } int main(){ int x,y; while(scanf("%d %d",&x,&y)!=EOF){ scanf("%s",&str); change(x,y); } return 0; }