http://acm.hust.edu.cn/vjudge/contest/122823#problem/A Solve equation

You are given two positive integers A and B in Base C. For the equation:

 

A=k*B+d

 

We know there always existing many non-negative pairs (k, d) that satisfy the equation above. Now in this problem, we want to maximize k.

 

For example, A="123" and B="100", C=10. So both A and B are in Base 10. Then we have:

(1) A=0*B+123

(2) A=1*B+23

As we want to maximize k, we finally get one solution: (1, 23)

 

The range of C is between 2 and 16, and we use 'a', 'b', 'c', 'd', 'e', 'f' to represent 10, 11, 12, 13, 14, 15, respectively.

Input

The first line of the input contains an integer T (T≤10), indicating the number of test cases.

 

Then T cases, for any case, only 3 positive integers A, B and C (2≤C≤16) in a single line. You can assume that in Base 10, both A and B is less than 2^31.

Output

For each test case, output the solution “(k,d)” to the equation in Base 10.       

Sample Input

3 2bc 33f 16 123 100 10 1 1 2

Sample Output

(0,700) (1,23) (1,0)
这个题我特别亏,因为最后代码写好怎么都不过,怎么都改不了,过后又找其他人来改,还是过不了,还把我气的不行,结果就是一个小问题,我真的是太粗心了,哎……同学说的对

#include<stdio.h> #include<string.h> int main() {     int T,i,k,C;     char A[100],B[100];     scanf("%d",&T);     while(T--)     {         scanf("%s%s%d",A,B,&C);         int l1=strlen(A);         int l2=strlen(B);         int s1=0,s2=0;         int m=C;         int C=1;         for(i=l1-1;i>=0;i--)         {             if(A[i]>='a')             {                 s1=s1+(A[i]-'a'+10)*C;                 C=C*m;             }             else             {                 s1=s1+(A[i]-'0')*C;                 C=C*m;             }         }         printf("%d\n",s1);         C=1;         for(k=l2-1;k>=0;k--)         {             if(B[k]>='a')             {                 s2=s2+(B[k]-'a'+10)*C;                 C=C*m;             }             else             {                 s2=s2+(B[k]-'0')*C;                 C=C*m;             }         }         int h=s1/s2,n=s1%s2;         printf("(%d,%d)\n",h,n);

    }     return 0; }

我是把i<l1-1;i>=0;i--;当时写的是l1>=0,就因为这,我一直过不了,还是要反省一下自己啊,哎……

还有就是注意技巧,C第二遍的时候置一,什么的,还有就是ASCII码,哎,愁人,你怎么那么笨……

posted @ 2016-07-19 20:35  小小姐  阅读(85)  评论(0编辑  收藏  举报