-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathday042.c
81 lines (71 loc) · 2.09 KB
/
day042.c
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
80
81
#include <stdio.h>
#include <string.h>
int main(void) {
char current_string[50], in_string[50];
char temp, continue_char;
int consecutive_flag = 1, char_count = 1, continue_flag = 1;
printf("Input the string\n");
scanf("%s", in_string);
// copy on current_string
for(int i=0; i<strlen(in_string); i++)
current_string[i] = in_string[i];
// sort current_string
for(int i=0; i<strlen(current_string); i++){
for(int j=i+1; j<strlen(current_string); j++){
if(current_string[i] > current_string[j]){
temp = current_string[i];
current_string[i] = current_string[j];
current_string[j] = temp;
}
}
}
// check consecutive
for(int i=0; i<strlen(current_string); i++){
for(int j=i+1; j<strlen(current_string); j++){
if(current_string[i] - current_string[j] == -1){
i++;
}else{
consecutive_flag = 0;
}
}
}
// print consecutive
if(consecutive_flag == 1){
printf("The string ");
for(int i=0; i<strlen(current_string); i++){
if(i == strlen(current_string)-1)
printf("'%c'", current_string[i]);
else
printf("'%c',", current_string[i]);
}
printf(" which are consecutive letters\n");
printf("All the letters occurs exactly once\n");
}else{
printf("The string ");
for(int i=0; i<strlen(in_string); i++){
if(i == strlen(in_string)-1)
printf("'%c'", in_string[i]);
else
printf("'%c',", in_string[i]);
}
printf(" which are not consecutive letters\n");
// charater count in char_count
for(int i=0; i<strlen(current_string); i++){
for(int j =i+1; j<strlen(current_string); j++){
if(current_string[i] == current_string[j]){
continue_char = current_string[i];
char_count++;
continue_flag = 0;
}
}
if(continue_flag == 0)
break;
}
// print char_count
if(char_count != 1)
printf("letter %c occurs %d time(s)\n", continue_char, char_count);
else
printf("All the letters occurs exactly once\n");
}
return 0;
}