-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path500_keyboard_row.c
More file actions
executable file
·79 lines (60 loc) · 1.51 KB
/
Copy path500_keyboard_row.c
File metadata and controls
executable file
·79 lines (60 loc) · 1.51 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdio.h>
#include <stdlib.h>
int inLine(char* letters, char letter) {
int i = 0;
while (letters[i]) {
if (letter == letters[i]) {
return 1;
}
i++;
}
return 0;
}
char** findWords(char** words, int wordsSize, int* returnSize) {
char a[] = "qwertyuiopQWERTYUIOP";
char b[] = "asdfghjklASDFGHJKL";
char c[] = "zxcvbnmZXCVBNM";
char** rows = (char **) malloc(sizeof(char *) * wordsSize);
int size = 0;
for (int i = 0; i < wordsSize; i++) {
char *letters = words[i];
int j = 0;
int row = 0;
int flag_a = 0, flag_b = 0, flag_c = 0;
int flag = 0;
while (letters[j] != '\0') {
if (inLine(a, letters[j])) {
flag_a = 1;
} else if (inLine(b, letters[j])) {
flag_b = 1;
} else if (inLine(c, letters[j])) {
flag_c = 1;
} else {
break;
}
flag = flag_a + flag_b + flag_c;
if (flag > 1) {
break;
}
j++;
}
if (flag == 1) {
rows[size] = letters;
size++;
}
}
*returnSize = size;
return rows;
}
int main() {
char *aa[20] = {"Hello", "Alaska", "Dad", "Peace"};
char **words = aa;
int i;
char **result = NULL;
int size;
result = findWords(words, 4, &size);
for (i = 0; i < size; i++) {
printf("%s\n", result[i]);
}
return 0;
}