1016. 部分A+B (15)

来源:互联网 发布:删除的sql语句怎么写 编辑:程序博客网 时间:2024/06/10 15:06

正整数A的“DA(为1位整数)部分”定义为由A中所有DA组成的新整数PA。例如:给定A = 3862767,DA = 6,则A的“6部分”PA是66,因为A中有2个6。

现给定A、DA、B、DB,请编写程序计算PA + PB

输入格式:

输入在一行中依次给出A、DA、B、DB,中间以空格分隔,其中0 < A, B < 1010

输出格式:

在一行中输出PA + PB的值。

输入样例1:
3862767 6 13530293 3
输出样例1:
399
输入样例2:
3862767 1 13530293 8
输出样例2:
0




//

//  PAT_1016.cpp

//  MyFirstProject

//

//  Created by 潘庆一 on 2017/4/27.

//  Copyright © 2017潘庆一. All rights reserved.

//


#include <stdio.h>

#include <iostream>

using namespacestd;


int main() {

    string str1, str2;

    char ch1, ch2;

    //采用字符串记录与数字

    cin >> str1 >> ch1 >> str2 >> ch2;

    

    int sum1 =0;

    int sum2 =0;

    int count1 =1;

    int count2 =1;

    

    for(int i=0; i < str1.length(); i++) {

        if(str1[i] == ch1) {

            //通过asc码对字符与数字转换, ‘1’----49

            sum1 += count1 * (ch1 - 48);

            count1 *= 10;

        }

    }

    

    for(int i=0; i < str2.length(); i++ ) {

        if(str2[i] == ch2) {

            sum2 += count2 * (ch2 - 48);

            count2 *= 10;

        }

    }

    

    cout << sum1 + sum2 <<endl;

    

    return0;

}


0 0