酷代码 AI
菜单
服务商
DeepSeek字节豆包讯飞星火
更多选项

C++实现统计字符串中特定字母数量

```cpp #include <iostream> #include <string> int main() { int n; std::cin >> n; std::string s; std::cin >> s; int r_count = 0, f_count = 0, m_count = 0, v_count = 0; for (int i = 0; i < n; ++i) { if (s[i] == 'r') { r_count++; } else if (s[i] == 'f') { f_count++; } else if (s[i] == 'm') { m_count++; } else if (s[i] == 'v') { v_count++; } } std::cout << r_count << " " << f_count << " " << m_count << " " << v_count << std::endl; return 0; } ``` ######[AI问答 | 226点数解答 | 2026-05-09 20:28:20]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]