杭电acm1002题C语言答案是什么???求高手!
#include<stdio.h>voidf(intg){chara[100],b[100],*A,*B;intc[100],i,*C;scanf("%c",a);sca...
#include<stdio.h>
void f(int g)
{
char a[100],b[100],*A,*B;
int c[100],i,*C;
scanf("%c",a);
scanf("%c",b);
A=a;B=b;
c[0]=0;
for(i=0;i<=101;i++)
{if(a[i]+b[i]-96>=10)
{c[i]+=(a[i]+b[i]-96)%10;
c[i+1]=1;}
else
c[i]=a[i]+b[i]-96;
}
C=c;
printf("case %d:\n%c+%c=%d\n",g,*A,*B,*C);
}
main()
{
int T,t;
scanf("%d",&T);
for(t=1;t<=T;t++)
f(t);
} 验证的没有错误,可就是执行不了,哪错了??
InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
OutputFor each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.
Sample Input2
1 2
112233445566778899 998877665544332211
Sample OutputCase 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110 展开
void f(int g)
{
char a[100],b[100],*A,*B;
int c[100],i,*C;
scanf("%c",a);
scanf("%c",b);
A=a;B=b;
c[0]=0;
for(i=0;i<=101;i++)
{if(a[i]+b[i]-96>=10)
{c[i]+=(a[i]+b[i]-96)%10;
c[i+1]=1;}
else
c[i]=a[i]+b[i]-96;
}
C=c;
printf("case %d:\n%c+%c=%d\n",g,*A,*B,*C);
}
main()
{
int T,t;
scanf("%d",&T);
for(t=1;t<=T;t++)
f(t);
} 验证的没有错误,可就是执行不了,哪错了??
InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
OutputFor each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.
Sample Input2
1 2
112233445566778899 998877665544332211
Sample OutputCase 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110 展开
4个回答
展开全部
额。。。。。。
1.。。。。scanf("%c",a);输入一个字符???改成%s骚年。。。
2。。。。。for(i=0;i<=101;i++)题目没有说输入的没个数都是101位吧。。如果输入的数没有101位你的c[i]=a[i]+b[i]-96; c[i]系统会给你随机数的。。。。
3。。。。加法是从个位开始加的吧,你的a[0]、b[0]应该是输入数的最高位吧,怎么是他们相加往c[1]进位????。。。。。。
问下你的:::验证的没有错误,可就是执行不了;是什么意思
顺带说下楼上的应该读下题目:Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
1.。。。。scanf("%c",a);输入一个字符???改成%s骚年。。。
2。。。。。for(i=0;i<=101;i++)题目没有说输入的没个数都是101位吧。。如果输入的数没有101位你的c[i]=a[i]+b[i]-96; c[i]系统会给你随机数的。。。。
3。。。。加法是从个位开始加的吧,你的a[0]、b[0]应该是输入数的最高位吧,怎么是他们相加往c[1]进位????。。。。。。
问下你的:::验证的没有错误,可就是执行不了;是什么意思
顺带说下楼上的应该读下题目:Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
追问
应该是1001,输错了,题目要求A、B不超过1000位,A、B的位数是变化的,C的位数确定不了。
还有,不是验证,是编译。。。。。
追答
额。。。101、1001都不重要,重点不是说他有多少位。。。关键是你的程序for(i=0;i2以后你的a[i]就是没有赋初值这样在c语言中是会出现狠严重的后果的。。。。。。编译不会有问题的,运行时就完了
如果还有问题的话hi我吧。。或者留言。。。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
#include"string.h"
#define max 1000+10
char a[max],b[max];
int main()
{ int i,j,T,k;
scanf("%d",&T);
for(k=0;k<T;k++)
{ int A[max]={0},B[max]={0};
scanf("%s%s",a,b);
int x=strlen(a);
int y=strlen(b);
for(i=0;i<x;i++)A[i]=a[x-1-i]-'0';
for(i=0;i<y;i++)B[i]=b[y-1-i]-'0';
int c=0;
for(i=0;i<max;i++)
{ int s=(A[i]+B[i]+c);
A[i]=s%10;
c=s/10;
}
printf("Case %d:\n%s + %s = ",k+1,a,b);
for( i=max-1;i>=0;i--) if(A[i])break;
for(j=i;j>=0;j--)
printf("%d",A[j]);
printf("\n");
if(k<T-1)
printf("\n");
}
return 0;
}
#include"string.h"
#define max 1000+10
char a[max],b[max];
int main()
{ int i,j,T,k;
scanf("%d",&T);
for(k=0;k<T;k++)
{ int A[max]={0},B[max]={0};
scanf("%s%s",a,b);
int x=strlen(a);
int y=strlen(b);
for(i=0;i<x;i++)A[i]=a[x-1-i]-'0';
for(i=0;i<y;i++)B[i]=b[y-1-i]-'0';
int c=0;
for(i=0;i<max;i++)
{ int s=(A[i]+B[i]+c);
A[i]=s%10;
c=s/10;
}
printf("Case %d:\n%s + %s = ",k+1,a,b);
for( i=max-1;i>=0;i--) if(A[i])break;
for(j=i;j>=0;j--)
printf("%d",A[j]);
printf("\n");
if(k<T-1)
printf("\n");
}
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这是答案
#include<stdio.h>
#include<string.h>
int main()
{
char op1[1002],op2[1002];
int c,i,j,n,m,s1[1002],s2[1002],len1,len2,count;
count=1;
scanf("%d",&n);
m=n;
while(m--)
{
memset(s1,0,1002*sizeof(int));
memset(s2,0,1002*sizeof(int));
scanf("%s",op1);
scanf("%s",op2);
len1=strlen(op1);
len2=strlen(op2);
c=0;
for(i=len1-1;i>=0;i--)
s1[c++]=op1[i]-'0';
c=0;
for(i=len2-1;i>=0;i--)
s2[c++]=op2[i]-'0';
for(i=0;i<1002;i++)
{
s1[i]+=s2[i];
if(s1[i]>=10)
{
s1[i]-=10;
s1[i+1]++;
}
}
printf("Case %d:\n",count++);
printf("%s + %s = ",op1,op2);
for(i=1001;i>=0;i--)
if(s1[i])
break;
for(j=i;j>=0;j--)
printf("%d",s1[j]);
printf("\n");
if(count!=n+1)
printf("\n");
}
return 0;
}
#include<stdio.h>
#include<string.h>
int main()
{
char op1[1002],op2[1002];
int c,i,j,n,m,s1[1002],s2[1002],len1,len2,count;
count=1;
scanf("%d",&n);
m=n;
while(m--)
{
memset(s1,0,1002*sizeof(int));
memset(s2,0,1002*sizeof(int));
scanf("%s",op1);
scanf("%s",op2);
len1=strlen(op1);
len2=strlen(op2);
c=0;
for(i=len1-1;i>=0;i--)
s1[c++]=op1[i]-'0';
c=0;
for(i=len2-1;i>=0;i--)
s2[c++]=op2[i]-'0';
for(i=0;i<1002;i++)
{
s1[i]+=s2[i];
if(s1[i]>=10)
{
s1[i]-=10;
s1[i+1]++;
}
}
printf("Case %d:\n",count++);
printf("%s + %s = ",op1,op2);
for(i=1001;i>=0;i--)
if(s1[i])
break;
for(j=i;j>=0;j--)
printf("%d",s1[j]);
printf("\n");
if(count!=n+1)
printf("\n");
}
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
题目呢?
追问
Input The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
追答
2.源程序
/* Note:Your choice is C IDE */
#include "stdio.h"
void main()
{ int n,i,t=0,y=0,m=0,k=0;
int sum[1000]={0}; int a[100][100];
printf("请输入数据组数:\n");
scanf("%d",&n);
while(m<n)
{ for(i=0;i<2;i++)
{ scanf("%ld", &a[m][i]);
sum[m]=sum[m]+a[m][i];
}
m++;
}
for(i=0;i<m;i++)
printf("Case%d:\n%ld + %ld = %ld\n\n",i+1,a[i][0],a[i][1],sum[i]);
}
3.本地计算机运行结果截图(咋看不见呢??)
4. OJ提交结果截图(截图最后一行为自己的提交结果)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询