1017. A除以B (20)
本题要求计算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>
#include<math.h>
#include<stdlib.h>
int main(){
char a[2000];
scanf("%s",a);
int b;
scanf("%d",&b);
int n = strlen(a);
int temp=0;
int flag = 0;
for(int i=0;i<n;i++){
temp = (a[i]-'0')+temp*10;
if(temp>=b){
printf("%d",temp/b);
flag = 1;
}
else if(flag){
printf("0");
}
temp = temp%b;
}
if(flag==0)
printf("0");
printf(" %d",temp);
}