This question is very skillful in reading data. It is just like reading data with scanf, and then converting the number of reads into a 10-digit system according to the base system.
#include<cstdio>#include<cstring>#include<cctype>using namespace std;int main(){ //freopen("in.txt","r",stdin); int cas,base,num1,num2; char str1[50],str2[50]; scanf("%d",&cas); while(cas--) { scanf("%s %s %d",str1,str2,&base); num1=num2=0; for(int i=0; str1[i]!='\0'; i++) { int a; if(isalpha(str1[i])) a=str1[i]-'a'+10; else a=str1[i]-'0'; num1=num1*base+a; } for(int i=0; str2[i]!='\0'; i++) { int a; if(isalpha(str2[i])) a=str2[i]-'a'+10; else a=str2[i]-'0'; num2=num2*base+a; } printf("(%d,%d)\n",num1/num2,num1%num2); } return 0;}
PS: This question teammate Wa is because the str1 and str2 arrays only open 10, and the array overflows.
"Higher Education Community Cup" third Fujian University Student Program Design Competition