// PTest.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <fstream> #include <cmath> #include <string> #include <iomanip> #include <algorithm> #include <stdio.h> //using namespace std; std::ifstream cin("in.txt"); std::ofstream cout("out.txt"); std::string big_plus(std::string a,std::string b,int& op,bool point_flag) { std::string reusult = ""; if ( a.length()<b.length()) { std::swap( a,b); } if (point_flag) { //小数部分的加法在后面补零 for (int i =a.length()-b.length();i>0;i--) { b = b+"0"; } } else { //整数部分的加法,在前面补零 for (int i =a.length()-b.length();i>0;i--) { b = "0"+b; } } int i,j,t; for (i = a.length()-1;i>=0;i--) { t = a[i]-'0'+b[i]-'0'+op; reusult += '0'+t%10; op = t/10; } std::reverse(reusult.begin(),reusult.end()); return reusult; } std::string big_point_plus(std::string a,std::string b) { std::string a_point_part; std::string b_point_part; std::string result_point_part; std::string result_int_part; std::string a_int_part; std::string b_int_part; int a_p = std::find(a.begin(),a.end(),'.')-a.begin(); int b_p = std::find(b.begin(),b.end(),'.')-b.begin(); a_int_part = a.substr(0,a_p); a_point_part = a.substr(a_p+1,a.length()); b_int_part = b.substr(0,b_p); b_point_part = b.substr(b_p+1,b.length()); int op = 0; //小数部分相加 result_point_part = big_plus(a_point_part,b_point_part,op,true); //整数部分的加法 result_int_part = big_plus(a_int_part,b_int_part,op,false); return result_int_part+"."+result_point_part; } int main(int argc, char* argv[]) { std::string a,b; while (cin>>a>>b) { cout<<big_point_plus(a,b)<<std::endl; } return 0; }