1016 Part A + B (B) (15 minutes)

  Positive integer A of "D * A ** (as an integer) portion" is defined as A * all * D ** A * new compositions integer P A . For example: Given A = 3862767, D A = 6, then A "section 6" of the * P ** A * 66, because A has two 6.

Now given A , D A , B , D B , write a program to calculate P A + P B .

Input formats:

  In the given input line are sequentially A , D A , B , D B , separated by a space, where 0 < A , B <1010.

Output formats:

  Output line P A + P B value.

Sample Input 1:

3862767 6 13530293 3   

Output Sample 1:

399        

Sample Input 2:

3862767 1 13530293 8        

Output Sample 2:

0

 


code show as below:

#include <stdio.h>
int main() {
    long  a, b, da, db; 
    scanf_s("%ld%ld%ld%ld", &a, &da, &b, &db);
    long  pa = 0, pb = 0;
    while (a != 0)
    {
        if (a % 10 == da){
            pa = pa * 10 + da;
            a = a / 10;
        }
        else
        {
            a /= 10;
            continue;
        }
    
    }
    while (b != 0)
    {
        if (b % 10 == db) {
        pb = pb * 10 + db;
        b /= 10;
        }
        else
        {
            b /= 10;
            continue;
        }
    }

    printf("%ld\n", pa + pb);
    return 0;
}

 


Failed Summary:

  1, when the error must be debugged! ! Be sure to debug! ! Want to find an input for an hour in the wrong order! !

  2, C basic grammar is not enough familiar with their contents are not confident! ! More practice, more practice! !

  3, this problem can only do with a long integer, string can be! (Before the code miscalculation or question order :()

  4, the above code is finished after the change after their own mistakes left and right to change, there may be some nonsense, I hope criticism! !

Guess you like

Origin www.cnblogs.com/Lance-WJ/p/12407508.html