-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvowel-consonant-separation.cpp
82 lines (71 loc) · 1.73 KB
/
vowel-consonant-separation.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool isVowel(char x)
{
x = tolower(x);
if (x == 'a' or x == 'e' or x == 'i' or x == 'o' or x == 'u')
{
return true;
}
return false;
}
int main()
{
ios_base ::sync_with_stdio(false);
cin.tie(nullptr);
vector<string> input;
string temp;
while (cin >> temp)
{
input.pb(temp);
}
vector<char> vowels, consonants;
vector<string> vowelWords, consonantWords;
for (int i = 0; i < input.size(); i++)
{
if (isVowel(input[i][0]))
{
vowelWords.pb(input[i]);
}
else consonantWords.pb(input[i]);
for (int j = 0; input[i][j]; j++)
{
if (isVowel(input[i][j]))
{
vowels.pb(input[i][j]);
}
else consonants.pb(input[i][j]);
}
}
cout << "Vowels - " << vowels.size() << "\n";
for (int i = 0; i < vowels.size(); i++)
{
if (i == vowels.size() - 1)
{
cout << vowels[i] << "\n";
continue;
}
cout << vowels[i] << ", ";
}
cout << "\nConsonants - " << consonants.size() << "\n";
for (int i = 0; i < consonants.size(); i++)
{
if (i == consonants.size() - 1)
{
cout << consonants[i] << "\n";
continue;
}
cout << consonants[i] << ", ";
}
cout << "\nString starting with vowels - " << "\n";
for (int i = 0; i < vowelWords.size(); i++)
{
cout << vowelWords[i] << " ";
}
cout << "\n\nString starting with consonants - " << "\n";
for (int i = 0; i < consonantWords.size(); i++)
{
cout << consonantWords[i] << " ";
}
}