-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount_repeat_time.c
More file actions
68 lines (52 loc) · 1.41 KB
/
count_repeat_time.c
File metadata and controls
68 lines (52 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
*计算数字重复出现的次数,如给定两个数组,都包含a-z,A-Z的英文字母,编程给出两个数组中都出现的字母
*
*
* */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void repeat_letter(char *a, char *b, int a_len, int b_len)
{
char *letter_a = malloc(26 * 2);
char *letter_b = malloc(26 * 2);
int i = 0;
memset(letter_a, 0, 26);
memset(letter_b, 0, 26);
for (i = 0; i < a_len; i++) {
if (a[i] >= 'a' && a[i] <= 'z') {
letter_a[a[i] - 'a'] = 1;
}
if (a[i] >= 'A' && a[i] <= 'Z') {
letter_a[a[i] - 'A' + 26] = 1;
}
}
for (i = 0; i < b_len; i++) {
if (b[i] >= 'a' && b[i] <= 'z') {
letter_b[b[i] - 'a'] = 1;
}
if (b[i] >= 'A' && b[i] <= 'Z') {
letter_b[b[i] - 'A' + 26] = 1;
}
}
for (i = 0; i < 26; i++) {
if (letter_a[i] == 1 && letter_b[i] == 1) {
printf("%c\n", 'a' + i);
}
}
for (i = 0; i < 26; i++) {
if (letter_a[i + 26] == 1 && letter_b[i + 26] == 1) {
printf("%c\n", 'A' + i);
}
}
free(letter_a);
free(letter_b);
return;
}
int main()
{
char test_a[10] = {'a', 'y', 'R', 'E', 'w', 'q', 'c', 'Q', 'x'};
char test_b[10] = {'t', 'y', 'e', 'o', 'O', 's', 'S', 'Q', 'x'};
repeat_letter(test_a, test_b, 10, 10);
return 0L;
}