| ||||||||||
| 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 | |||||||||
shuiyige#include <iostream>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
void add(char *a, char *b, int la, int lb, char *res){
int carry = 0;
int i;
for(i = 0; i < la || i < lb; i++){
if(i<la) carry += (a[i]-'0');
if(i<lb) carry += (b[i]-'0');
res[i] = (carry%10) + '0';
carry /= 10;
}
while(carry > 0){
res[i] = (carry%10)+'0';
carry /= 10;
i++;
}
}
int main() {
int n;
scanf("%d", &n);
while(n--){
char a[1000], b[1000];
scanf("%s%s",a,b);
int la = strlen(a), lb = strlen(b);
char res[2000] = {'\0'};
add(a,b,la,lb,res);
char *st = res;
while(st[0] == '0') st++;
int lr = strlen(res);
int pos = lr-1;
while(res[pos] == '0'){
res[pos] = '\0';
pos--;
}
printf("%s\n", st);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator