PAT乙级 1017. A除以B (20)

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


 1 #include "stdio.h"
 2 #include"string.h"
 3 #include <stdlib.h>
 4 int main()
 5 {
 6     char a[1001];
 7     int ge,shi,i,count,b=7;
 8     gets(a);
 9     count=strlen(a);
10     b=a[count-1]-'0';
11     shi=a[0]-'0';
12     ge=a[1]-'0';
13     if(count<=3)
14         printf("%d %d",shi/b,shi%b );
15     else
16        { 
17         if(count==4)
18            printf("%d %d",(shi*10+ge)/b,(shi*10+ge)%b ); 
19         else
20             {
21              for(i=2;i<count-1;i++)
22                  {
23                     printf("%d",(shi*10+ge)/b );
24                     shi =(shi*10+ge)%b;
25                     ge=a[i]-'0';
26                  }
27                printf(" %d",shi );
28             }
29 
30        }
31     return 0;
32 }

 

posted @ 2016-10-01 20:48  乐乐章  阅读(831)  评论(0编辑  收藏  举报