算法笔记

A+B

#include 
#include 
#include
#include
#include
#include
using namespace std;

int main()
{
    char str1[15];
    char str2[15];
    while (scanf("%s%s",str1,str2)!=EOF) {
        int i = 0;
        int j = 1;
        int sum1=0;
        for (i = strlen(str1); i > 0; i--) {
            if (str1[i] >= '0' && str1[i] <= '9') {
                sum1 += (str1[i] - 48) * j;
                j = j * 10;
            }
        }
        if (str1[0] == '-') {
            sum1 = -sum1;
        }
        int sum2 = 0;
        j = 1;
        for (i = strlen(str2); i >= 0; i--) {
            if (str2[i] >= '0' && str2[i] <= '9') {
                sum2 += (str2[i] - 48) * j;
                j = j * 10;
            }
        }
        if (str2[0] == '-') {
            sum2 = -sum2;
        }
        cout << sum1+sum2<< endl;
        
    }
    return 0;
}

你可能感兴趣的:(算法笔记)