题解 | 计算某字符出现次数

#include <cctype>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main() {
    string line;
    // 第一行输入
    getline(cin, line);
    // 字符输入:
    char c;
    cin >> c;
    c = tolower(c);
    int count = -1;

    if (line.size() <= 1000 && line.size() >= 1) {
        count = 0;
        char tmpc;
        for (int i = 0; i != line.size(); ++i) {
            tmpc = line[i];
            tmpc = tolower(tmpc);
            if (c == tmpc)
            {
                ++count;
            }
        }    
    }

    cout << count << endl;
    
    return 0;
}

全部评论

相关推荐

05-21 15:47
门头沟学院 Java
浪漫主义的虹夏:项目有亮点吗,第一个不是纯玩具项目吗,项目亮点里类似ThreadLocal,Redis储存说难听点是花几十分钟绝大部分人都能学会,第二个轮子项目也没体现出设计和技术,想实习先沉淀,好高骛远的自嗨只会害了自己
点赞 评论 收藏
分享
昨天 12:17
已编辑
商丘师范学院 Java
后来123321:别着急,我学院本大二,投了1100份,两个面试,其中一个还是我去线下招聘会投的简历,有时候这东西也得看运气
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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