-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq1.4.cpp
More file actions
51 lines (43 loc) · 1.24 KB
/
q1.4.cpp
File metadata and controls
51 lines (43 loc) · 1.24 KB
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
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void calculate_frequencies(string *in_string, vector<int> *avail_indices,
int *hash_table) {
int index;
char c;
for (string::iterator it = in_string->begin(); it != in_string->end(); it++) {
c = *it;
c = toupper(c);
index = (int)c;
if ((index >= 65) && (index < 91)) {
if ((*(hash_table + index)) == 0)
avail_indices->push_back(index);
(*(hash_table + index))++;
}
}
}
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv) {
string input_string;
int hash_table[256] = {0};
bool odd_frequency_flag = false;
vector<int> available_indices;
int index;
cout << "enter input string: ";
getline(cin, input_string);
calculate_frequencies(&input_string, &available_indices, hash_table);
for (vector<int>::iterator it = available_indices.begin();
it != available_indices.end(); it++) {
index = *it;
// cout << (char)index << " :" << hash_table[index] << "\n";
if (hash_table[index] % 2 != 0) {
if (odd_frequency_flag == true) {
cout << "False\n";
return 0;
} else
odd_frequency_flag = true;
}
}
cout << "True\n";
return 0;
}