读书人

20进制的加法程序求教解决思路

发布时间: 2012-02-11 09:51:35 作者: rapoo

20进制的加法程序求教
20进制的加法运算应该很简单吧,各位大侠看下我的程序:
#include <stdio.h>

void reverse(char *s);

main()
{
char one[100],two[100],result[100];
int first,second,counter,temp,i,m,n;
while(1)
{
if(scanf( "%s ",one)==EOF)
break;
scanf( "%s ",two);
reverse(one);
reverse(two);
counter=0;
i=0;
m=n=0;
while(one[m]!= '\0 '&&two[n]!= '\0 ')
{
if(one[m]> = '0 '&&one[m] <= '9 ')
first=one[m]- '0 ';
else if(one[m]> = 'a '&&one[m] <= 'j ')
first=one[m]- 'a '+10;
if(two[n]> = '0 '&&two[n] <= '9 ')
second=two[n]- '0 ';
else if(two[n]> = 'a '&&two[n] <= 'j ')
second=two[n]- 'a '+10;
temp=first+second+counter;
if(temp> =20)
{
counter=1;
temp-=20;
}
else counter=0;
if(temp> =0&&temp <=9)
result[i++]=temp+ '0 ';
else result[i++]=temp-10+ 'a ';
m++;n++;


}
while(one[m]!= '\0 ')
{
if(one[m]> = '0 '&&one[m] <= '9 ')
first=one[m]- '0 ';
else if(one[m]> = 'a '&&one[m] <= 'j ')
first=one[m]- 'a '+10;
temp=first+counter;
if(temp> =20)
{
counter=1;
temp-=20;
}
else counter=0;
if(temp> =0&&temp <=9)
result[i++]=temp+ '0 ';
else result[i++]=temp-10+ 'a ';
m++;
}
while(two[n]!= '\0 ')
{
if(two[n]> = '0 '&&two[n] <= '9 ')
second=two[n]- '0 ';
else if(two[n]> = 'a '&&two[n] <= 'j ')
second=two[n]- 'a '+10;
temp=second+counter;
if(temp> =20)
{
counter=1;
temp-=20;
}
else counter=0;


if(temp> =0&&temp <=9)
result[i++]=temp+ '0 ';
else result[i++]=temp-10+ 'a ';
n++;
}
result[i]= '\0 ';
reverse(result);
printf( "%s\n ",result);
}
}

void reverse(char s[])
{
char ch;
int i, j;

for(j = 0; s[j] != '\0 '; j++)
{
}

--j;

for(i = 0; i < j; i++)
{
ch = s[i];
s[i] = s[j];
s[j] = ch;
--j;
}

}
本地运行能够通过,在ACM上为什么会说为是错误答案呢??
题目地址为:http://acm.zju.edu.cn/show_problem.php?pid=1205
希望大家赐教了。。。

[解决办法]
不会是因为没有返回值就说错误
[解决办法]
包哈 不很的 呵呵
[解决办法]
在acm上他们是有一定的规范的,可能你的程序很对,但是你和他们的规范不一样,这样他们用他们的测试数据来测试你的程序就会不通过。这是非专业人士的主要错误。

读书人网 >C语言

热点推荐