1017. A除以B (20)

xiaoxiao2021-02-28  127

本题要求计算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 <stdio.h> #include <string.h> int main() { char a[1100]; int temp=0,i,b,q,r,flag=0; scanf("%s %d",a,&b); for(i=0;i<strlen(a);i++) { temp=temp*10+a[i]-'0'; if(temp>=b) { printf("%d",temp/b); temp=temp%b; } else { if(flag) printf("0"); else if(!flag && strlen(a)==1) printf("0"); } flag=1; } printf(" %d",temp); return 0; }
转载请注明原文地址: https://www.6miu.com/read-61760.html

最新回复(0)