题解 | #统计字符#

统计字符

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

定义string变量,想要读入空格,可以用getline函数,参数为(cin,变量)

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

int main() {
    string str1,str2;
    while (getline(cin,str1) && str1[0] != '#') { 
        int count;
        getline(cin, str2);
        for (int i = 0; i < str1.size(); i++){
            count = 0;
            for (int j = 0; j < str2.size(); j++)
                if (str1[i] == str2[j])
                    count++;
            cout << str1[i] << " "<< count << endl;	//按格式输出
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

01-30 16:13
浙江大学 Java
点赞 评论 收藏
分享
码农索隆:以下是我以我微薄的认知提供的建议: 1.考个教师资格证,去当体育考试。 2.去健身房当健身教练(因为在我印象里面体育生身材都不错)。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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