题解 | #统计字符#

统计字符

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);
        }
    }

    

}

全部评论

相关推荐

肥罗且玫瑰:没啥用,没人看这个,这个公司比较离谱查看图片
点赞 评论 收藏
分享
10-25 22:20
门头沟学院 Java
代码飞升:同学院本,个人亮点去了,打招呼里面的废话也去了,学院本就是路边一条,明天拉满然后该学还是学,小厂也行尽量先有一段实习。另外你的项目描述写的不好,具体列一下可被提问的点,然后量化一下指标或者收益吧
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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