-
Notifications
You must be signed in to change notification settings - Fork 0
/
alphabet-count.cpp
61 lines (54 loc) · 1.18 KB
/
alphabet-count.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
#include <bits/stdc++.h>
using namespace std;
int main()
{
char ch;
vector <char> inputStr;
int countLen = 1;
while(cin.get(ch))
{
if(ch == '\n')
{
break;
}
else if(countLen == 1 && ch == '.')
{
cout << "Masukan tidak boleh diawali karakter '.' (titik)\n";
exit(1);
}
else if (countLen > 100)
{
cout << "Masukan melebihi 100 karakter\n";
exit(1);
}
else if(ch != ' ' && ch != '.')
{
inputStr.push_back(tolower(ch));
}
countLen++;
}
vector <int> position;
for(int i = 'a'; i <= 'z'; i++)
{
int count = 0, index = 0;
for(char _ch: inputStr)
{
if(_ch == i)
{
count++;
position.push_back(index);
}
index++;
}
if(count != 0)
{
cout << char(i) << ": " << count << " kali pada ";
for(int _index: position)
{
cout << _index << ", ";
}
cout << '\n';
}
position.clear();
}
}