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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值