1017. A除以B (20)
时间限制
100 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
本题要求计算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<fstream>
#include<iostream>
#include<string>
using namespace std;
int main()
{
// ifstream cin("bbb.txt");
string s;
int first=0,temp=0;
int b;
cin>>s>>b;
for(int i=0;i<s.length();i++)
{
temp=temp*10+s[i]-48;
if(temp>=b)
{
cout<<temp/b;
first=1;
}
else if(first)
cout<<0;
temp=temp%b;
}
if(first==0)
cout<<0;
cout<<" "<<temp;
return 0;
}
评测结果
时间 | 结果 | 得分 | 题目 | 语言 | 用时(ms) | 内存(kB) | 用户 |
---|---|---|---|---|---|---|---|
5月01日 18:47 | 答案正确 | 20 | 1017 | C++ (g++ 4.7.2) | 1 | 312 | 沈健 |
测试点
测试点 | 结果 | 用时(ms) | 内存(kB) | 得分/满分 |
---|---|---|---|---|
0 | 答案正确 | 1 | 256 | 12/12 |
1 | 答案正确 | 1 | 312 | 2/2 |
2 | 答案正确 | 1 | 312 | 2/2 |
3 | 答案正确 | 1 | 312 | 2/2 |
4 | 答案正确 | 1 | 256 | 2/2 |