YT 督促训练 fzoj 2012Solve equation 各种进制转换为10进制
2016-04-25 17:42
459 查看
A - Solve equation
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice FZU
2102
Description
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)
再次注意字符转化为数字
A - Solve equation
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice FZU
2102
Description
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 <iostream> #include<string.h> #include<cstdio> #include<cmath> #define ll long long using namespace std; int zhuanhuan(char a[],int c)///将任意进制转化为10进制 { int i=0; int sum=0; int b[1000]={0}; int len=strlen(a); for(i=0;i<len;i++) { /* switch(a[i]) { case 'a':b[i]=10;break; case 'b':b[i]=11;break; case 'c':b[i]=12;break; case 'd':b[i]=13;break; case 'e':b[i]=14;break; case 'f':b[i]=15;break; default:b[i]=a[i]-'0';break; } */ if(a[i]>=0&&a[i]<='9') b[i]=a[i]-'0'; else b[i]=a[i]-'a'+10; } for(int j=0;j<len;j++) sum+=b[j]*pow(c,len-j-1); return sum; } int main() { char x[1000],y[1000]; int t,a,b,c; scanf("%d",&t); while(t--) { scanf("%s%s%d",&x,&y,&c); a=zhuanhuan(x,c); b=zhuanhuan(y,c); if(a<b) printf("(0,%d)\n",a); else { printf("(%d,%d)\n",a/b,a%b); } } return 0; }
再次注意字符转化为数字
相关文章推荐
- C#进制之间的相互转换详解
- js数值和和字符串进行转换时可以对不同进制进行操作
- Python内置函数bin() oct()等实现进制转换
- C++实现十六进制字符串转换为十进制整数的方法
- javascript十六进制及二进制转化的方法
- php实现将任意进制数转换成10进制的方法
- 使用Python内置的模块与函数进行不同进制的数的转换
- python实现基本进制转换的方法
- Python 26进制计算实现方法
- 进制转换
- java中四种进制的转换
- C#生成短地址+任意进制转换
- 进制转换
- 黑马程序员——Java基础——Java中几种进制的相互转换
- [DanoR][Java小码][将double转换为不同进制后用String输出]
- 10bit数和12bit数的转换
- cout 以2/8/10/16进制输出
- 位运算符
- c语言基础学习记录第一天
- java中的进制(jdk内置的进制转换方法)