题目网址:http://acm.fzu.edu.cn/problem.php?pid=2102
题目大意:给出数a,b和进制bas,a和b都是bas进制的数,现在要计算十进制数k和d ,使得a = k * b + d。所以求得k = a / b, d =a - (a/b) * b.
思路:我们先将a,b转换成十进制数,然后根据公式直接输出即可
#include"iostream"
using namespace std;int changeBase(string num, int b) {int len =num.length();int ans = 0, k;for (int i = 0; i < len; i++) {if (num[i] >= '0' && num[i] <= '9') k = num[i] - '0';else k = num[i] - 'a' + 10;ans = ans * b + k;}//cout<<ans<<endl;;return ans;
}
int main()
{int t;string a,b;int bas;cin>>t;while(t--){cin>>a>>b>>bas;int beg=changeBase(a,bas);int end=changeBase(b,bas);int k=beg/end;int d=beg-(beg/end)*end;cout<<'('<<k<<","<<d<<')'<<endl;}return 0;
}