2013
12-12

# 九度-1003-A+B[解题代码]

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

-111111101
2346912

java 代码如下：

import java.io.BufferedInputStream;
import java.math.BigInteger;
import java.util.Scanner;

public class Main{
static BigInteger b1,b2;
public static void main(String[] args) {
Scanner s = new Scanner(new BufferedInputStream(System.in));
while(s.hasNext()){
b1 = new BigInteger(s.next().replaceAll(",", ""));
b2 = new BigInteger(s.next().replaceAll(",", ""));
}
}

}
/**************************************************************
Problem: 1003
User: coder
Language: Java
Result: Accepted
Time:160 ms
Memory:16032 kb
****************************************************************/

C语言代码如下：

#include<stdio.h>
#include<math.h>

int main(void)
{
char name1[81],name2[81],temp;
int C[20];
int i=0,j;
int conversion(char name[]);

while(scanf("%s%s",name1,name2)!=EOF)
{

if(name1[0]=='-' && name2[0]=='-')
C[i]=-(conversion(name1) + conversion(name2));
else if(name1[0]=='-' && name2[0] != '-')
C[i]= conversion(name2)-conversion(name1) ;
else if(name1[0]!='-' && name2[0] == '-')
C[i]= conversion(name1)-conversion(name2) ;
else
C[i]= conversion(name2)+conversion(name1) ;

printf("%d\n",C[i]);
i++;
}

return 0;
}

int conversion(char name[])
{
char *ptr;
char temp;
int l=0,i=0,A=0;
ptr = name;
if(name[0] == '-')
{
temp='-';
i=1;
ptr++;
}

while(*(ptr++)!='\0')
{
if(*ptr != ',')
l++;    //除去逗号和正负的长度

}

while(name[i]!='\0')
{
//  printf("i=%d %c\n",i,name1[i]);
if(name[i] != ',')
{

A+=(name[i]-'0') * pow(10,--l);
//  printf("过程A=%d",A);
}
i++;
}
//  printf("A=%d",A);
return A;
}
/**************************************************************
Problem: 1003
User: sophiaaaaa
Language: C
Result: Accepted
Time:0 ms
Memory:1004 kb
****************************************************************/