blob: 6cf79e8dcf909caf42f0c87736c461981d1e3cba (
plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
#include <iostream>
/*
*
* 5.12
*
*
*/
/*
The solution for this exercise is pretty ugly i will admit.
One other thing to note here is that the exercise can be
interpreted in various different ways. Should it count all
occurances of fl, ff, fi in one counter? Or should they all
have their own counters? I went with the first one but this
could just as well be the latter interpretation. I actually
thought this would be easy going in to it but i struggled
with bugs where i input strings like "fafafafa". Because it
would still count because whenever it encounters characters
that aren't f, i, l it does not reset the factive variable
so i added factive = false; to all the if statement blocks.
Again, not pretty but it did the job.
*/
int main () {
char Character = 0;
uint32_t Va = 0;
uint32_t Ve = 0;
uint32_t Vi = 0;
uint32_t Vo = 0;
uint32_t Vu = 0;
uint32_t BlankSpace = 0;
uint32_t Tabs = 0;
uint32_t Newlines = 0;
uint32_t Other = 0;
uint32_t ffflfi = 0;
bool factive = false;
while(std::cin.get(Character)) {
if(Character == 'a' || Character == 'A') {
++Va;
factive = false;
} else if (Character == 'e' || Character == 'E') {
++Ve;
factive = false;
} else if (Character == 'i' || Character == 'I') {
if(factive) {
++ffflfi;
factive = false;
}
++Vi;
} else if (Character == 'o' || Character == 'O') {
++Vo;
factive = false;
} else if (Character == 'u' || Character == 'U') {
++Vu;
factive = false;
} else if (Character == 'f') {
if(factive) {
++ffflfi;
factive = false;
continue;
}
factive = true;
} else if (Character == 'l') {
if(factive) {
++ffflfi;
factive = false;
}
} else if (Character == '\n') {
++Newlines;
factive = false;
} else if (Character == '\t') {
++Tabs;
factive = false;
} else if (Character == ' ') {
++BlankSpace;
factive = false;
} else {
++Other;
factive = false;
}
}
std::cout << "A: " << Va << "\n"
<< "E: " << Ve << "\n"
<< "I: " << Vi << "\n"
<< "O: " << Vo << "\n"
<< "U: " << Vu << "\n"
<< "Tabs: " << Tabs << "\n"
<< "Newlines: " << Newlines << "\n"
<< "Blank Space: " << BlankSpace << "\n"
<< "ffflfi: " << ffflfi << "\n"
<< "Others: " << Other << std::endl;
return 0;
}
|