#include "stdio.h" #include "string" #include "algorithm" using namespace std; char buf[110][110]; int n = 0;//记录输入的行数为(n-1) string addString(string num1,string num2){//字符串相加 int length = num1.size()>num2.size()?num1.size():num2.size(); while (num1.size() < length) num1 = "0" + num1;//补齐高位 while (num2.size() < length) num2 = "0" + num2;//同理,补齐高位 string num3 = "";int carry = 0; int temp; for (int i = length-1; i >= 0; --i) { temp = num1[i]-'0' + num2[i]-'0'+carry; if (temp > 9){ num3 += temp-10+'0'; carry = 1; } else{ num3 += temp+'0'; carry = 0; } } if (carry == 1) num3 += '1'; reverse(num3.begin(),num3.end()); return num3; } void Init(string &num1){//字符串初始化,消去前导0 int i = 0; while (num1[i] == '0') ++i; num1.erase(0,i); } int main(){ while (scanf("%s",buf[n++])!=EOF){ string num = buf[n-1]; if (num == "0") break; } n = n-1; string sum = ""; for (int i = 0; i < n; ++i) { string num = buf[i]; Init(num); sum = addString(sum,num); } printf("%s",sum.c_str()); }