|
1 | 1 | #include <stdio.h>
|
2 | 2 | #include <stdlib.h>
|
3 | | -#include<conio.h> |
4 | | -int main() |
| 3 | + |
| 4 | + |
| 5 | +void enter_string(char* message, char* s, size_t s_size) { |
| 6 | + printf("%s", message); |
| 7 | + fgets(s, s_size, stdin); |
| 8 | +} |
| 9 | + |
| 10 | +int get_score(char* s) |
5 | 11 | {
|
6 | | - int i,a2,g=0,p,a1,s2=0,b,s1=0; |
7 | | - char s[1000],st[1000]; |
8 | | - printf("Enter The First Name: "); |
9 | | - fgets(s, sizeof(s), stdin); |
10 | | - for ( i = 0; s[i] != '0円'; i++); |
11 | | - a1=i-1; |
12 | | - printf("Enter The Second Name: "); |
13 | | - fgets(st, sizeof(st), stdin); |
14 | | - for ( i = 0; st[i] != '0円'; i++); |
15 | | - a2=i-1; |
16 | | - for(int j=0;j<a1;j++) |
17 | | - { |
18 | | - b=(int) s[j]; |
19 | | - |
20 | | - if(s[j]==' ') |
| 12 | + char *end; |
| 13 | + for (end = s; *end != '0円'; ++end); |
| 14 | + --end; |
| 15 | + |
| 16 | + if (end == s) |
21 | 17 | {
|
22 | | - continue; |
| 18 | + printf("wrong Input\n"); |
| 19 | + return -1; |
23 | 20 | }
|
24 | | - else if(s[j]>='A'&&s[j]<='Z') |
25 | | - { |
26 | | - s1=s1+(b-64)*5; |
27 | | - } |
28 | | - else if(s[j]>='a'&&s[j]<='z') |
| 21 | + |
| 22 | + int score = 0; |
| 23 | + char c; |
| 24 | + for(char* p = s; p != end; ++p) |
29 | 25 | {
|
30 | | - s1=s1+(b-96)*5; |
31 | | - } |
| 26 | + c = *p ^ 0x20; |
| 27 | + |
| 28 | + if(c == ' ') |
| 29 | + { |
| 30 | + continue; |
| 31 | + } |
| 32 | + else if(c >= 'A' && c <= 'Z') |
| 33 | + { |
| 34 | + score += c - '@'; |
| 35 | + } |
32 | 36 | else
|
33 | 37 | {
|
34 | 38 | printf("wrong Input\n");
|
35 | | - g=12; |
36 | | - break; |
37 | | - } |
38 | | - |
| 39 | + return-1; |
| 40 | + } |
| 41 | + } |
| 42 | + returnscore*5 / (end-s); |
39 | 43 | }
|
40 | | -s1=s1/a1; |
41 | 44 |
|
| 45 | +int main() |
| 46 | +{ |
| 47 | + int p,s1,s2; |
| 48 | + char name[1000]; |
42 | 49 |
|
43 | | - for(int j=0;j<a2;j++) |
44 | | - { |
45 | | - b=(int) st[j]; |
46 | | - |
47 | | - if(st[j]==' ') |
| 50 | + while(1) |
48 | 51 | {
|
49 | | - continue; |
50 | | - } |
| 52 | + do |
| 53 | + { |
| 54 | + enter_string("Enter The First Name: ", name, sizeof(name)); |
| 55 | + s1 = get_score(name); |
| 56 | + } while (s1 == -1); |
51 | 57 |
|
52 | | - else if(st[j]>='A'&&st[j]<='Z') |
53 | | - { |
54 | | - s2=s2+(b-64)*5; |
55 | | - } |
56 | | - else if(st[j]>='a'&&st[j]<='z') |
57 | | - { |
58 | | - s2=s2+(b-96)*5; |
59 | | - } |
| 58 | + do |
| 59 | + { |
| 60 | + enter_string("Enter The Second Name: ", name, sizeof(name)); |
| 61 | + s2 = get_score(name); |
| 62 | + } while (s2 == -1); |
| 63 | + |
| 64 | + if(s2 > s1) |
| 65 | + { |
| 66 | + p = (s1 * 100) / s2; |
| 67 | + } |
60 | 68 | else
|
61 | 69 | {
|
62 | | - printf("wrong Input\n"); |
63 | | - g=12; |
64 | | - break; |
65 | | - } |
66 | | - |
67 | | -} |
68 | | -s2=s2/a2; |
| 70 | + p = (s2 * 100) / s1; |
| 71 | + } |
69 | 72 |
|
70 | | -if(g!=12) |
71 | | -{ |
72 | | -if(s2>s1) |
73 | | -{ |
74 | | - p=(s1*100)/s2; |
75 | | -} |
76 | | -else |
77 | | -{ |
78 | | - p=(s2*100)/s1; |
79 | | -} |
80 | | -char ch='%'; |
81 | | -printf("The love Percentage is : %d %c\n",p,ch); |
82 | | -} |
83 | | -else |
84 | | -{ |
85 | | - printf("Input Error\n"); |
86 | | -} |
87 | | -printf("\n pls Follow me 🌟 if you like this code 😊\n"); |
88 | | - return main(); |
| 73 | + printf("The love Percentage is : %d %% \n",p); |
| 74 | + printf("\n pls Follow me 🌟 if you like this code 😊\n"); |
| 75 | + } |
| 76 | + return 0; |
89 | 77 | }
|
90 | 78 |
|
91 | 79 |
|
|
0 commit comments