Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <algorithm>
- #include <set>
- #include <unordered_set>
- using namespace std;
- bool check_word(string word, unordered_set <string>& dict, unordered_set <string>& lower_case_dict) {
- if (dict.find(word) != dict.end()) {
- return true;
- }
- string lower_case_word = word;
- transform(lower_case_word.begin(), lower_case_word.end(), lower_case_word.begin(), ::tolower);
- if (lower_case_dict.find(lower_case_word) != lower_case_dict.end()) {
- return false;
- }
- int upper_char = 0;
- if (dict.find(word) == dict.end()) {
- const char* char_word = word.c_str();
- for (int i = 0; i < word.length(); i++) {
- if (char_word[i] == toupper(tolower(char_word[i]))) {
- upper_char++;
- }
- }
- }
- if (upper_char != 1) {
- return false;
- }
- return true;
- }
- void task9() {
- int n;
- cin >> n;
- unordered_set <string> dict;
- for (int i = 0; i < n; i++) {
- string word;
- cin >> word;
- dict.insert(word);
- }
- unordered_set <string> lower_case_dict;
- for (auto word : dict) {
- transform(word.begin(), word.end(), word.begin(), ::tolower);
- lower_case_dict.insert(word);
- }
- cin.ignore();
- string sentence;
- getline (cin, sentence);
- istringstream stream(sentence);
- string word;
- int wrong_words_count = 0;
- while (stream >> word) {
- if (!(check_word(word, dict, lower_case_dict))) {
- wrong_words_count++;
- }
- }
- cout << wrong_words_count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement