CSES - Datatähti 2021 alku - Results
Submission details
Task:Sanalista
Sender:Lentsu
Submission time:2020-10-05 19:43:30 +0300
Language:C++ (C++11)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#2ACCEPTED0.01 sdetails
#3ACCEPTED0.01 sdetails

Code

#include <iostream>
#include <map>

int main() {

	int number_of_words;
	std::cin >> number_of_words;

	int sum_of_even_words = 0;
	std::string word;

	std::map<char, int> ocs;
	bool b;

	for(int i = 0; i != number_of_words; ++i){
		
		//get word from input stream
		std::cin >> word;

		//set validity-boolean to true
		b = true;
	
		//A word with even number of specific characters can't have an odd length 
	
			for(std::string::const_iterator it = word.begin(); it != word.end(); ++it)
				if(ocs.find(*it) == ocs.end())
					//add character occurence to map
					ocs.insert(std::make_pair(*it, 1));
				else
					//increment occurences
					++ocs[*it];

			for(std::map<char, int>::const_iterator it = ocs.begin(); it != ocs.end(); ++it)
				if(it->second % 2 != 0)
					//if an odd number of occurences, set validity to false
					b = false;

			if(b)
				++sum_of_even_words;

			//clear the character occurence map
			ocs.clear();
		}
	
	std::cout << sum_of_even_words << std::endl;

	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