题解 | #统计字符#

统计字符

https://www.nowcoder.com/practice/4ec4325634634193a7cd6798037697a8

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


int C_time(string str,char pattern)
{
    int pos = 0;
    int count = 0;
    pos = str.find(pattern, pos);
    while (pos != str.npos)
    {
        count++;
        pos = str.find(pattern, pos+1);
    }
    return count;
    
}

int main()
{
    string str1, str2;
    while (getline(cin,str1))
    {
        if (str1 == "#")
        {
            break;
        }
        getline(cin, str2);
        for (int i = 0; i < str1.size(); i++)
        {
            int times = C_time(str2, str1[i]);
            printf("%c %d\n",str1[i],times);
        }
    }

    

}

全部评论

相关推荐

07-01 17:14
中北大学 Java
兄弟们是真是假
牛客46374834...:我在boss上投java岗从来没成功过
点赞 评论 收藏
分享
争当牛马还争不上
码农索隆:1.把简历改哈 2.猛投,狠投 3.把基础打牢 这样你在有机会的时候,才能抓住
点赞 评论 收藏
分享
鬼迹人途:你去投一投尚游游戏,服务器一面,第一个图算法,做完了给你一个策略题,你给出方案他就提出低概率问题,答不上当场给你挂
点赞 评论 收藏
分享
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 15:39
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务