-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflames.c
More file actions
75 lines (62 loc) · 1.65 KB
/
Copy pathflames.c
File metadata and controls
75 lines (62 loc) · 1.65 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
#include <stdio.h>
#include <string.h>
#include <ctype.h>
/* Remove common characters */
void removeCommon(char a[], char b[]) {
for (int i = 0; a[i] != '\0'; i++) {
for (int j = 0; b[j] != '\0'; j++) {
if (a[i] == b[j] && a[i] != '*') {
a[i] = '*';
b[j] = '*';
break;
}
}
}
}
/* Count remaining characters */
int countRemaining(char str[]) {
int count = 0;
for (int i = 0; str[i] != '\0'; i++) {
if (str[i] != '*')
count++;
}
return count;
}
/* FLAMES logic */
void flamesResult(int count) {
char flames[] = "FLAMES";
int len = 6;
int index = 0;
while (len > 1) {
index = (index + count - 1) % len;
for (int i = index; i < len - 1; i++) {
flames[i] = flames[i + 1];
}
len--;
}
printf("\nResult: ");
switch (flames[0]) {
case 'F': printf("Friends\n"); break;
case 'L': printf("Love\n"); break;
case 'A': printf("Affection\n"); break;
case 'M': printf("Marriage\n"); break;
case 'E': printf("Enemy\n"); break;
case 'S': printf("Siblings\n"); break;
}
}
int main() {
char name1[50], name2[50];
printf("Enter first name: ");
scanf("%s", name1);
printf("Enter second name: ");
scanf("%s", name2);
// Convert to lowercase
for (int i = 0; name1[i]; i++)
name1[i] = tolower(name1[i]);
for (int i = 0; name2[i]; i++)
name2[i] = tolower(name2[i]);
removeCommon(name1, name2);
int total = countRemaining(name1) + countRemaining(name2);
flamesResult(total);
return 0;
}