A+B

Problem C:例4006 A+B問題

Time Limit:1000MS  Memory Limit:65536K
Total Submit:442 Accepted:109

Description

給定兩個整數A和B,其表示形式是:從個位開始,每三位數用逗號","隔開。
現在請計算A+B的結果,並以正常形式輸出。

Input

輸入包含多組數據,每組數據佔一行,由兩個整數A和B組成(-10^9 < A,B < 10^9)。

Output

請計算A+B的結果,並以正常形式輸出,每組數據佔一行。

Sample Input

-234,567,890 123,456,789
1,234 2,345,678

Sample Output

-111111101
2346912

#include <cstdio>
#include <cstring>
#include <cstdlib>
long long int ctoi(char *p){
	int len=strlen(p);
	long long int c=0;
	int i;
	for (i = 0; i < len; ++i)
	{
		if (p[i]==','||p[i]=='-')
		{
			continue;
		}
		else
		{
			c=c*10+p[i]-'0';
		}
	}
	if(strchr(p,'-')!=NULL)
	{
       c=0-c;
	}

    return c;
}
int main()
{
	char a[15],b[15];
	while(scanf("%s%s",a,b)!=EOF)
	{
		long long int x;
		x=ctoi(a)+ctoi(b);
		printf("%lld\n",x);
	}


	return 0;
}


注意整數的長度。用long long int , %lld





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章