加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

PAT乙级1016

发布时间:2020-12-16 10:47:11 所属栏目:百科 来源:网络整理
导读:题目链接 https://pintia.cn/problem-sets/994805260223102976/problems/994805306310115328 题解 很简单,遍历两个字符串,找到da或db,然后不断更新pa和pb即可。 // PAT BasicLevel 1016// https://pintia.cn/problem-sets/994805260223102976/problems/99

题目链接

https://pintia.cn/problem-sets/994805260223102976/problems/994805306310115328

题解

很简单,遍历两个字符串,找到da或db,然后不断更新pa和pb即可。

// PAT BasicLevel 1016
// https://pintia.cn/problem-sets/994805260223102976/problems/994805306310115328

#include <iostream>
#include <string>
using namespace std;

int main()
{
    // 获取a、da、b和db
    string a,b;
    char da,db;
    cin >> a >>da >> b >> db;

    // 计算pa
    int pa=0;
    for(int i=0;i<a.length();++i){
        if(a[i]==da){
            pa=pa*10+da-'0';
        }
    }

    // 计算pb
    int pb = 0;
    for (int i = 0; i < b.length(); ++i){
        if (b[i] == db){
            pb = pb * 10 + db - '0';
        }
    }

    // 输出结果
    cout << pa+pb;

    //system("pause");
    return 0;
}

作者:@臭咸鱼

转载请注明出处:https://www.cnblogs.com/chouxianyu/

欢迎讨论和交流!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读