当前位置:网站首页>PAT乙级-B1016 部分A+B(15)
PAT乙级-B1016 部分A+B(15)
2022-08-03 14:20:00 【nekoha_dexter】
正整数 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<109。
输出格式:
在一行中输出 PA+PB 的值。
输入样例 1:
3862767 6 13530293 3
输出样例 1:
399
输入样例 2:
3862767 1 13530293 8
输出样例 2:
0#include<iostream>
#include<string>
using namespace std;
int main(){
string a,b;
int Da, Db, Pa = 0,Pb = 0;
cin >> a >> Da >> b >> Db;
for(int i = 0 ; i < a.size(); ++i)
if(a[i] - '0' == Da) Pa = Pa * 10 + Da;
for(int i = 0; i < b.size() ;++i)
if(b[i] - '0' == Db) Pb = Pb * 10 + Db;
cout << Pa + Pb << endl;
return 0;
}
边栏推荐
猜你喜欢
随机推荐
位级运算之提取位级表示的最高位
淘特:引擎还是包袱?
MMA安装及使用优化
Ansible中的角色使用
The difference between servlet and jsp _ the difference between servlet and class
varchar2和varchar2(char)_datetime数据类型
进程通信的方式
哥斯拉加密WebShell过杀软
PostgreSQL V14中更好的SQL函数
“芯片法案”通过后,美光承诺在美国扩产
System learning Shell regular expressions
UE4 解决C盘缓存问题
GMapping principle analysis/easy to understand
LeetCode15:三数之和
15 years of software architect experience summary: In the ML field, 5 pits that beginners have stepped on
投资75亿卢比!印度宣布建首座存储芯片组装和封测工厂,将于12月量产
ITSM软件与工单系统的区别是什么?
选择合适的 DevOps 工具,从理解 DevOps 开始
ffplay视频播放原理分析
想成为网络安全技术爱好者(可能是黑客)的话,需要看什么书?









