题目描述
本题要求计算 A/B,其中 A 是不超过 1000 位的正整数,B 是 1 位正整数。你需要输出商数 Q 和余数 R,使得 A=B×Q+R 成立。
输入格式:
输入在一行中依次给出 A 和 B,中间以 1 空格分隔。
输出格式:
在一行中依次输出 Q 和 R,中间以 1 空格分隔。
输入样例:
123456789050987654321 7
输出样例:
17636684150141093474 3
C++解法
#include<iostream>
using namespace std;
int main(){
string s;
int a,t=0,temp=0;
cin>>s>>a;
int len=s.length();
t=(s[0]-'0')/a;
if((t!=0&&len>1)||len==1)
cout<<t;
temp=(s[0]-'0')%a;
for(int i=1;i<len;i++){
t=(temp*10+s[i]-'0')/a;
cout<<t;
temp=(temp*10+s[i]-'0')%a;
}
cout<<" "<<temp;
return 0;
}
python解法
A, B = tuple(map(int, input().split()))
print(str(A//B)+' '+str(A%B))
哈哈,这次总算是Python比较简单了