题目:
题目大意:
给出方程A = k*B + d, 题目给出A、B、C的值,C是进制数。求出最大的 k ,输出(k,d)的值。
进制数:以C进制进行运算。
eg: 12 的 8 进制为 1 * 8 + 2 = 10
解题思路:
首先给出A,B的字符串,根据C算出他们各自的值,然后进行运算即可。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
int main(){
int t;
scanf("%d",&t);
while(t--){
char St1[1005],St2[1005]; // 两个数组存放A,B的值。
int c;
ll num1 = 0; // A的值
ll num2 = 0; // B的值
scanf("%s %s %d",St1,St2,&c);
for (int i = 0; i < strlen(St1);i++){ // 计算A的数值
if (St1[i] >= 'a' && St1[i] <= 'f'){
num1 = num1 * c + (St1[i]-'a'+10);
}
else{
num1 = num1 * c + (St1[i]-'0');
}
}
for (int i = 0; i < strlen(St2);i++){ // 计算B的数值
if (St2[i] >= 'a' && St2[i] <= 'f'){
num2 = num2 * c + (St2[i]-'a'+10);
}
else{
num2 = num2 * c + (St2[i]-'0');
}
}
int k = num1 / num2; // 计算最大的K
int d = num1 % num2; // 计算 d 的值
printf("(%d,%d)\n",k,d); //进行输出
}
return 0;
}