Task: | Sanalista |
Sender: | jogr |
Submission time: | 2020-09-28 16:04:47 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 100 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | ACCEPTED | 0.01 s | details |
#3 | ACCEPTED | 0.01 s | details |
Code
#include <iostream> #include <string> #include <vector> using namespace std; struct letter { char c; int num; }; bool is_even(int num) { return !(num & 1); } bool has_even_letters(string str) { vector<letter> letters; letters.push_back(letter()); // get number of characers in the word for (uint i = 0; i < str.length(); i++) { bool applied = false; for (uint x = 1; x < letters.size(); x++) { // add to current counter, if found if (str.at(i) == letters[x].c) { letters[x].num++; applied = true; break; } } // create new counter, if not already existing if (!applied) { letter l; l.c = str.at(i); l.num = 1; letters.push_back(l); } } // check if there is even number of each letter for (uint i = 1; i < letters.size(); i++) { // starts from 1, because of the empty struct at 0 if (!is_even(letters[i].num)) return false; } return true; } int main() { int num; vector<string> str; cin >> num; for (int i = 0; i < num; i++) { string s; cin >> s; str.push_back(s); } int counter = 0; // get number of the words for (uint i = 0; i < str.size(); i++) { if (has_even_letters(str[i])) counter++; } cout << counter; return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
1000 korvata sopimusaika nuhatartunta korttiautomaatti ... |
correct output |
---|
15 |
user output |
---|
15 |
Test 2
Verdict: ACCEPTED
input |
---|
1000 pub hansikaslokero erikoisvalmisteinen unijukka ... |
correct output |
---|
42 |
user output |
---|
42 |
Test 3
Verdict: ACCEPTED
input |
---|
1000 haapalastu toipumisaika mustalaiskieli taidelainaamo ... |
correct output |
---|
70 |
user output |
---|
70 |