本题要求计算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
#include
using namespace std;
int main(){
string str,ans;
int n,d = 0;
cin >> str >> n;
for(int i = 0; i <= str.size()-1; i++){
int current = d * 10 + (str[i]-'0');
ans += (current / n+'0');
d = current % n;
}
for(int i = (ans[0] == '0' && ans.size()!=1)?1:0; i < ans.size(); i++)
cout << ans[i];
cout << " " << d;
return 0;
}
比一比谁的短:)