题目链接
实现
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
string A="", Q="";
int B, R;
cin >> A >> B ;
int len = strlen(A.c_str());
int tempDividend = 1, yushu = 0,tempRes=0;
if (len == 1)
{
sscanf(A.c_str(), "%d", &tempDividend);
tempRes = tempDividend / B;
yushu = tempDividend % B;
Q.append(to_string(tempRes));
}
else
{
int i = 0;
string tempstr = "";
for (i; i < len; i++)
{
tempstr.append(to_string(A[i]-'0'));
sscanf(tempstr.c_str(), "%d", &tempDividend);
if (tempDividend<B)
{
if (i != 0)
{
Q.append("0");
}
continue;
}
else
{
Q.append(to_string(tempDividend / B));
yushu = tempDividend % B;
tempstr = "";
if (yushu)
tempstr.append(to_string(yushu));
}
}
}
cout << Q << " " << yushu;
return 0;
}