Skip to content

Commit c9dc039

Browse files
author
wangzhijie01
committed
wangzhijie add for 查找一串字符中数字出现次数
1 parent b6ab257 commit c9dc039

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*************************************************************************
2+
> File Name: numappeartimes.c
3+
> Author: wangzhijie
4+
5+
> Created Time: 2020年04月28日 星期二 15时27分28秒
6+
************************************************************************/
7+
8+
#include<stdio.h>
9+
#include <stdlib.h>
10+
#include <string.h>
11+
12+
13+
14+
15+
16+
int arr[10] = {
17+
0
18+
};
19+
20+
21+
int main()
22+
{
23+
char buf[100];
24+
25+
while(scanf("%s", buf) != EOF){
26+
int size = strlen(buf);
27+
int i;
28+
for(i = 0;i < size; i++){
29+
switch(buf[i]){
30+
case 48:
31+
arr[0]++;
32+
break;
33+
case 49:
34+
arr[1]++;
35+
break;
36+
case 50:
37+
arr[2]++;
38+
break;
39+
case 51:
40+
arr[3]++;
41+
break;
42+
case 52:
43+
arr[4]++;
44+
break;
45+
case 53:
46+
arr[5]++;
47+
break;
48+
case 54:
49+
arr[6]++;
50+
break;
51+
case 55:
52+
arr[7]++;
53+
break;
54+
case 56:
55+
arr[8]++;
56+
break;
57+
case 57:
58+
arr[9]++;
59+
break;
60+
default:
61+
printf("it's not number!\n");
62+
break;
63+
}
64+
}
65+
for(i = 0; i < 10; i++){
66+
printf("数字%d出现的次数:%d\n",i,arr[i]);
67+
}
68+
69+
}
70+
71+
return 0;
72+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
这个初级算法题太easy

0 commit comments

Comments
 (0)