您的位置:首页 > 其它

PAT乙级 1017. A除以B

2018-03-31 13:48 302 查看

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);
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: