现在的位置: 首页 > 综合 > 正文

165 查找出每个字符的个数

2018年01月19日 ⁄ 综合 ⁄ 共 391字 ⁄ 字号 评论关闭

65、华为面试
char *str = "AbcABca";
写出一个函数,查找出每个字符的个数,区分大小写,要求时间复杂度是 n(提示用 ASCⅡ码)

/*
65、华为面试
qq5823996
char *str = "AbcABca";
写出一个函数,查找出每个字符的个数,区分大小写,要求时间复杂度是 n(提示用 ASC
Ⅱ码)
*/
#include<iostream>
#include<stdio.h>
using namespace std;

int main() 
{ 
	char *str="AbcABca"; 
	int count[256]={0}; 
	for (char *p=str;*p!='\0';p++) 
		count[*p]++;  
		 
	for (int i=0;i<256;i++)   
		if(count[i]>0)   //有个数大于零的,就打印出来
			printf("The count of %c is: %d\n",i,count[i]); 
			 
	return 0; 
}

抱歉!评论已关闭.