本題要求計算A/B,其中A是不超過1000位的正整數,B是1位正整數。你需要輸出商數Q和余數R,使得A = B * Q + R成立。
輸入格式:
輸入在1行中依次給出A和B,中間以1空格分隔。
輸出格式:
在1行中依次輸出Q和R,中間以1空格分隔。
輸入樣例:
123456789050987654321 7
輸出樣例:
17636684150141093474 3
#include <iostream>
#include <string>
using namespace std;
int main()
{
string A;
int B;
cin>>A>>B;
int temp=0,guard=0;
for(int i=0;i<A.length();++i){
temp=temp*10+A[i]-48;
if(temp>=B){
cout<<temp/B;
guard=1;
}
else if(guard) cout<<0;
temp=temp%B;
}
if(guard==0) cout<<0;
cout<<" "<<temp<<endl;
return 0;
}