PAT B-1016 部分A+B

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

现给定 A、D?A??、B、D?B??,请编写程序计算 P?A??+P?B??。

输入格式:

输入在一行中依次给出 A、D?A??、B、D?B??,中间以空格分隔,其中 0。

输出格式:

在一行中输出 P?A??+P?B?? 的值。

输入样例 1:

3862767 6 13530293 3

输出样例 1:

399

输入样例 2:

3862767 1 13530293 8

输出样例 2:

0实现:

# include<cstdio>

int main(){

long long number1,number2,d1,d2;//十的十次方大于int ,用long long 存储

scanf("%lld%lld%lld%lld", &number1, &d1, &number2, &d2);

long long pa=0,pb=0;

while(number1!=0){//枚举每一位数,若等于d,则累成赋值给pa

if(number1%10==d1) pa=pa*10+d1;

number1=number1/10;

}

while(number2!=0){

if(number2%10==d2) pb=pb*10+d2;

number2=number2/10;

}

printf("%lld\n", pa+pb);

return 0;

}

原文地址:https://www.cnblogs.com/lzdxh027/p/11305142.html

时间: 2024-08-03 18:02:49

PAT B-1016 部分A+B的相关文章

PAT乙级 1016. 部分A+B (15)

1016. 部分A+B (15) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 正整数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

pat甲级1016

1016 Phone Bills (25)(25 分) A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts conn

PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)

1016 Phone Bills (25 分)   A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connec

PAT:1016. 部分A+B (15) AC

当做字符串处理#include<stdio.h> #include<string.h> int main() { char A[120],B[120],ca,cb; int iA=0,iB=0; scanf("%s %c %s %c",A,&ca,B,&cb); int lenA=strlen(A),lenB=strlen(B); int addA=0,addB=0; while(lenA!=-1) //遍历每一位,是目标数就处理 { int t

PAT(A) 1016. Phone Bills (25)

A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a long-distance call,

PAT 乙级 1016

1 #include <iostream> 2 #include <cmath> 3 using namespace std; 4 5 int main() { 6 int a = 0, da = 0; 7 int b = 0, db = 0; 8 cin >> a >> da >> b >> db; 9 int cnta = 0, cntb = 0; 10 int chu = a, yu = 0; 11 while (chu >

PAT乙级1016.部分A+B(15 分)

正整数 A 的“D?A??(为 1 位整数)部分”定义为由 A 中所有 D?A?? 组成的新整数 P?A??.例如:给定 8,D?A??=6,则 A 的“6 部分”P?A?? 是 66,因为 A 中有 2 个 6. 现给定 A.D?A??.B.D?B??,请编写程序计算 P?A??+P?B??. 输入格式: 输入在一行中依次给出 A.D?A??.B.D?B??,中间以空格分隔,其中 0. 输出格式: 在一行中输出 P?A??+P?B?? 的值. 输入样例 1: 3862767 6 1353029

PAT 1016. Phone Bills

PAT 1016. Phone Bills A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting

PAT 乙级真题 1006.1016.部分A+B

PAT 乙级真题 1006.1016.部分A+B 题目描述 正整数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的值. 输入样例 386276

1016. Phone Bills (25)——PAT (Advanced Level) Practise

题目信息: 1016. Phone Bills (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending