正整数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
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int A = cin.nextInt(); int DA = cin.nextInt(); int B = cin.nextInt(); int DB = cin.nextInt(); int count_A = 0; int count_B = 0; int res_A = 0; int res_B = 0; while (A != 0) { if (DA == A % 10) { count_A++; } A /= 10; } while (B != 0) { if (DB == B % 10) { count_B++; } B /= 10; } for (int i = 0; i < count_A; i++) { res_A = res_A * 10 + DA; } for (int i = 0; i < count_B; i++) { res_B = res_B * 10 + DB; } System.out.println(res_A + res_B); } }
1016. 部分A+B (15),布布扣,bubuko.com
原文地址:http://blog.csdn.net/jason_wang1989/article/details/25006787