1017. A除以B (20)卡壳

xiaoxiao2021-02-28  119

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<iostream> #include<cmath> using namespace std; int a[1000],b[1000],tmp=0; int main() { int i=0; while(scanf("",&a[i])!=EOF) ++i; int n=a[i-1]; i-=2; for(int j=0;j<=i;++j) { b[j]=(tmp*10+a[j])/n; tmp=((tmp*10+a[j])%n); } for(int j=0,flag=0;j<=i;++j) { if(b[j]>0||i==0)flag=1;//错误点:如果被除数只有一位则需输出0商 if(flag) { printf("%d",b[j]); } } printf(" %d",tmp); return 0; }

转载请注明原文地址: https://www.6miu.com/read-49823.html

最新回复(0)