本题要求计算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; string str; string z; int yu; void Div(int chu) { bool DouFlag = false; int t; for(int i = 0; i < str.length(); ++i) { if(DouFlag) t = yu*10+(str[i]-'0'); else t = str[i]- '0'; if(t < chu) { yu = t; if(i != 0) z += '0'; DouFlag = true; continue; } if(t%chu != 0) DouFlag = true; else DouFlag = false; z += t/chu + '0'; yu = t%chu; } } int main() { int chu; cin>>str>>chu; if((str.length() == 1) && (str[0] < chu + '0')) cout<<0<<" "<<str[0]; else { Div(chu); cout<<z<<" "<<yu<<endl; } return 0; }