A+B

A+B

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 79   Accepted Submission(s) : 29

Font: Times New Roman | Verdana | Georgia

Font Size:

Problem 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

Source

浙大计算机研究生复试上机考试-2010年
#include<iostream>
#include<string>
#include <stdlib.h> 
using namespace std;
int sum(string e,string f)//数值转换
{
    int le,lf;
    int x=0,y=0;
    le=e.length()-1;
    lf=f.length()-1;
    if(e[0]=='-')
    {    
        for(int i=1;i<=le;i++)
    {
    
        x=x*10+e[i]-'0';
        
    
    
    }
        x=x*(-1);
    }
    else
    {
        for(int i=0;i<=le;i++)
    {
    
        x=x*10+e[i]-'0';
        
    
    
    }
    
    
    }
    if(f[0]=='-')
    {

    for(int j=1;j<=lf;j++)
    {
        
        y=y*10+f[j]-'0';
        
    
    }
    y=y*(-1);
    }
    else
    {
        for(int j=0;j<=lf;j++)
    {
        
        y=y*10+f[j]-'0';
        
    
    }
    
    
    }


return x+y;
}
void check(string &e,string &f)//去掉,号
{
    
    for(int i=0;i<e.length();i++)
    {
        if(e[i]==',') 
        {
            e.erase(i,1);
            
        }
    
    
    }
    for(int j=0;j<f.length();j++)
    {
        if(f[j]==',') 
        {
            f.erase(j,1);
            
        }
    
    
    }


}
int main()
{
    int a,b;
    string c,d;
    int summ;
    while(cin>>c>>d)
    {
        check(c,d);
        summ=sum(c,d);
        cout<<summ<<endl;

        

    
    
    
    
    }




}
原文地址:https://www.cnblogs.com/2013lzm/p/3254003.html