| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:一次AC,上代码In Reply To:一次AC,上代码 Posted by:hero19930 at 2010-06-19 10:29:06 #include <stdio.h>
#include <string.h>
void Add(char a[], char b[], char c[])
{
int len;
int i, x = 0;
if(a[0] > b[0])
len = a[0];
else
len = b[0];
for(i = 1; i <= len; i++)
{
x = x / 10 + a[i] + b[i];
c[i] = x % 10;
}
c[i] = x / 10;
c[0] = i;
while(c[c[0]] == 0 && c[0] > 0)
c[0]--;
}
int main()
{
char a[100], b[100], c[100], t[100];
int i;
for(i = 0; i < 100; i++)
a[i] = b[i] = c[i] = t[i] = 0;
scanf("%s", t);
a[0] = strlen(t);
for(i = 1; i <= a[0]; i++)
a[i] = t[a[0] - i] - '0';
scanf("%s", t);
b[0] = strlen(t);
for(i = 1; i <= b[0]; i++)
b[i] = t[b[0] - i] - '0';
Add(a, b, c);
for(i = c[0]; i >= 1; i--)
printf("%d", c[i]);
printf("\n");
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator