Solve equation
来源:互联网 发布:软件售后工程师发展 编辑:程序博客网 时间:2024/05/05 18:07
Description
You are given two positive integers A and B in Base C. For the equation:
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
Sample Input
Sample Output
(0,700)
(1,23)
(1,0)
题意:属于进制转换,比较简单的一道题,首先将A、B两个数转换为10进制,然后直接输出A/B,A%B;
<span style="font-size:14px;"># include <cstdio># include <cstring># include <iostream>using namespace std;char a[1000],b[1000];int c,A,B;void exchange(char *a,char *b,int c){ A=B=0; int i; for(i=0;i<strlen(a);i++) { A*=c; switch(a[i]) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0': A+=a[i]-48; break; default: A+=a[i]-87; } } for(i=0;i<strlen(b);i++) { B*=c; switch(b[i]) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0': B+=b[i]-48; break; default: B+=b[i]-87; } }}int main(){ int T; cin>>T; while(T--) { int k; scanf("%s%s%d",&a,&b,&c); exchange(a,b,c); printf("(%d,%d)\n",A/B,A%B); } return 0;}</span>
- Solve equation
- Solve equation
- Solve equation
- Solve equation
- Solve equation
- FZOJ2102:Solve equation
- FZU 2102 Solve equation
- FZU 2102 Solve equation
- FZU - 2102 Solve equation
- FZU-2102-Solve equation
- FZU 2102Solve equation
- 640. Solve the Equation
- 640. Solve the Equation
- Solve the Equation
- Can you solve this equation?
- FZU Problem 2102 Solve equation
- Can you solve this equation?
- Can you solve this equation?
- C++11 bind的使用陷阱
- TCP/IP小摘
- 第四章字符串和多维数组
- perhaps the designated entry point is not set
- 我的U3D 学习之旅
- Solve equation
- 数组去重
- 面试必会函数源代码 strcpy/memcpy/atoi/kmp/quicksort
- 第五章 树和二叉树
- 学习Linux之前需要掌握编程能力么?
- 利用AsyncHttpClient获取网络文本
- 通过坑、蒙、拐、骗、偷这5点,教你如何做好市场
- Audiophobia
- 【转】数据结构C#版笔记--队列(Quene)