我是靠谱客的博主 沉默树叶,这篇文章主要介绍C++字符统计,现在分享给大家,希望可以做个参考。

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

int main(){
	
	string str = "";
       //char str[200];
	cin >> str;
       //cin.getline(str,200);
	int cnt[256]={};

	for(int i = 0; i < str.size(); i++)
//for(int i =0; i < strlen(str); i++)
{ cnt[(int)str[i]]++; } for(int i = 0; i < 256; i++){ if(cnt[i] != 0){ cout << (char)i << ":" << cnt[i]<< endl; } } return 0; }

PS:使用注释部分可以读取空格和标点符号字符。

转载于:https://www.cnblogs.com/Podevor/archive/2011/06/19/2788198.html

最后

以上就是沉默树叶最近收集整理的关于C++字符统计的全部内容,更多相关C++字符统计内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部