牛客网PAT练兵场-部分A+B

题解:简单循环

题目地址:https://www.nowcoder.com/questionTerminal/fb581ea099a14f5d97c6149cbeee249f

/**
*
*作者:Ycute
*时间:2019-11-01-15.13.53
*题目简单描述:简单循环取出相应的数即可
*/


#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;


int main(){
    int A,a1,B,b1;
    scanf("%d %d %d %d",&A,&a1,&B,&b1);
    int temp1=0,temp2=0;
    while(A){
        int t;
        t=A%10;
        A/=10;
        if(t==a1){
            temp1=temp1*10+a1;
        }
    }
    while(B){
        int t;
        t=B%10;
        B/=10;
        if(t==b1){
            temp2=temp2*10+b1;
        }
    }
    printf("%d\n",temp1+temp2);
    return 0;
}

 

posted @ 2019-11-01 15:30  LifeRunningError  Views(168)  Comments(0Edit  收藏  举报