Skip to content

Commit e23335a

Browse files
author
wangzhijie01
committed
wangzhijie modify for 字符串中字符出现的次数
1 parent c9dc039 commit e23335a

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*************************************************************************
2+
> File Name: charappearstimes.c
3+
> Author: wangzhijie
4+
5+
> Created Time: 2020年04月28日 星期二 16时46分46秒
6+
************************************************************************/
7+
8+
#include<stdio.h>
9+
#include <string.h>
10+
#include <stdlib.h>
11+
#include <assert.h>
12+
13+
14+
void hashchar(char *buf)
15+
{
16+
int *arr = (int *)malloc(sizeof(int) * 256);
17+
memset(arr, 0, sizeof(int) * 256);
18+
19+
int i, size;
20+
size = strlen(buf);
21+
for(i = 0; i < size; i++){
22+
arr[buf[i]]++;
23+
}
24+
for(i = 0; i < 256; i++){
25+
if(arr[i] != 0){
26+
printf("char:%c, appeartimes:%d\n", i, arr[i]);
27+
}
28+
}
29+
}
30+
31+
32+
33+
34+
int main()
35+
{
36+
37+
char buf[256] = {
38+
0
39+
};
40+
41+
while(scanf("%s", buf) != EOF){
42+
hashchar(buf);
43+
}
44+
45+
return 0;
46+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
使用hash表就能实现,easy!

0 commit comments

Comments
 (0)