标签:print 多个 没有 for strlen lib div str strong
本题要求计算A/B,其中A是不超过1000位的正整数,B是1位正整数。你需要输出商数Q和余数R,使得A = B * Q + R成立。
输入格式:
输入在1行中依次给出A和B,中间以1空格分隔。
输出格式:
在1行中依次输出Q和R,中间以1空格分隔。
输入样例:
123456789050987654321 7
输出样例:
17636684150141093474 3
这道题找了老半天的错,在本机调试多个答案都正确,但提交后却都不对,最后发现是temp没有赋初值0。以后得多加注意
1 #include<stdio.h> 2 #include<string.h> 3 #include<math.h> 4 #include<stdlib.h> 5 int main(){ 6 char a[2000]; 7 scanf("%s",a); 8 int b; 9 scanf("%d",&b); 10 int n = strlen(a); 11 int temp=0; 12 int flag = 0; 13 for(int i=0;i<n;i++){ 14 temp = (a[i]-‘0‘)+temp*10; 15 if(temp>=b){ 16 printf("%d",temp/b); 17 flag = 1; 18 } 19 else if(flag){ 20 printf("0"); 21 } 22 temp = temp%b; 23 } 24 if(flag==0) 25 printf("0"); 26 printf(" %d",temp); 27 }
标签:print 多个 没有 for strlen lib div str strong
原文地址:http://www.cnblogs.com/lolybj/p/6185466.html