zoukankan      html  css  js  c++  java
  • 1016 部分A+B (15 分)

    1016 部分A+B (15 分)

    正整数 AAA 的“DAD_ADA​​(为 1 位整数)部分”定义为由 AAA 中所有 DAD_ADA​​ 组成的新整数 PAP_APA​​。例如:给定 A=3862767A = 3862767A=3862767,DA=6D_A = 6DA​​=6,则 AAA 的“6 部分”PAP_APA​​ 是 66,因为 AAA 中有 2 个 6。

    现给定 AAA、DAD_ADA​​、BBB、DBD_BDB​​,请编写程序计算 PA+PBP_A + P_BPA​​+PB​​。

    输入格式:

    输入在一行中依次给出 AAA、DAD_ADA​​、BBB、DBD_BDB​​,中间以空格分隔,其中 0<A,B<10100 < A, B < 10^{10}0<A,B<1010​​。

    输出格式:

    在一行中输出 PA+PBP_A + P_BPA​​+PB​​ 的值。

    输入样例 1:

    3862767 6 13530293 3
    

    输出样例 1:

    399
    

    输入样例 2:

    3862767 1 13530293 8
    

    输出样例 2:

    0
    思路:
      注意判断字符串为空的情况
      stl中count函数用于计数,使用方法count(iter.begin(),iter.end(),item),返回值即为所求。
      另外stoll()函数可把数字型string转换成long long
    #include<iostream>
    #include<string>
    #include<vector>
    #include<string>
    #include<cstdio>
    #include<cmath>
    #include<string.h>
    #include<algorithm>
    #include<map>
    #include<stack>
    using namespace std;
    
    int main()
    {
        string a,b,tempa="",tempb="";
        char da,db;
        cin>>a>>da>>b>>db;
        int num1=count(a.begin(),a.end(),da);
        int num2=count(b.begin(),b.end(),db);
        while(num1>0)
        {
            tempa+=da;
            num1--;
        }
        while(num2>0)
        {
            tempb+=db;
            num2--;
        }
        if(tempa=="")
            tempa="0";
        if(tempb=="")
            tempb="0";
        cout<<stoll(tempa)+stoll(tempb);
        return 0;
    }


  • 相关阅读:
    POJ 2752 Seek the Name, Seek the Fame
    POJ 2406 Power Strings
    KMP 算法总结
    SGU 275 To xor or not to xor
    hihocoder 1196 高斯消元.二
    hihoCoder 1195 高斯消元.一
    UvaLive 5026 Building Roads
    HDU 2196 computer
    Notions of Flow Networks and Flows
    C/C++代码中的笔误
  • 原文地址:https://www.cnblogs.com/zhanghaijie/p/10401433.html
Copyright © 2011-2022 走看看