This problem is not very difficult, but to understand the different types of conversion. Talk less, first on the code
#include <iostream>#include<string>using namespacestd;intMain () {stringb; while(cin>>a>>B) { Longnum1=0, num2=0; for(intI=0; I<a.length (); i++){ if(a[i]>='0'&& a[i]<='9') {NUM1=num1*Ten+a[i]-'0'; } } for(intI=0; I<b.length (); i++){ if(b[i]>='0'&& b[i]<='9') {num2=num2*Ten+b[i]-'0'; } } if(a[0]=='-') {NUM1=0-NUM1; } if(b[0]=='-') {num2=0-num2; } cout<<num1+num2<<Endl; } return 0;}/************************************************************** problem:1003 user:hg2013211626 language:c++ result:accepted time:0 Ms memory:1520 kb****************************************************************/
According to the requirements of the topic, each of the three numbers is separated, so I use string input here. Before I defined two long data, the first step of the program was to convert the string type to a long type. Here I use a For loop, in order to determine the string of each letter, if the content is greater than 0 less than 9, then convert it to a number, the specific method to see above (very ingenious method) and then directly calculated.
Topic 1003:a+b