zoukankan      html  css  js  c++  java
  • A+B (带有,的数字)

    题目描述

    给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开。 现在请计算A+B的结果,并以正常形式输出。

    输入描述:

    输入包含多组数据数据,每组数据占一行,由两个整数A和B组成(-10^9 < A,B < 10^9)。

    输出描述:

    请计算A+B的结果,并以正常形式输出,每组数据占一行。

    输入

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

    输出

    -111111101
    2346912
    
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int fun(string s){
    	int n = 0;
    	for(int i = 0; i < s.size(); i++){
    		if(s[i] >= '0' && s[i] <= '9'){
    			n = n * 10 + (s[i] - '0');// 十进制数每次在末尾加一位就是这个十进制数乘于10再加上这个数
    		}
    	}
    	if(s[0] == '-') return 0 - n;
    	else return n;
    }
    
    int main(){
    	string s1, s2;
    	int a, b;
    	while(cin >> s1 >> s2){
    		a = fun(s1);
    		b = fun(s2);
    		cout << a + b << endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    L1-021 重要的话说三遍
    L1-020 帅到没朋友
    pytest--钩子
    pytest--allure
    pytest--常用插件
    pytest--高级用法
    pytest--配置文件
    pytest--控制运行
    pytest--fixture
    pytest--使用前提
  • 原文地址:https://www.cnblogs.com/zhuobo/p/10289498.html
Copyright © 2011-2022 走看看