Advertisement
TwITe

Untitled

Aug 21st, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. bool check_word(string word, unordered_set <string> dict) {
  2.     int upper_char = 0;
  3.     if (dict.find(word) != dict.end()) {
  4.         return true;
  5.     }
  6.     if (dict.find(word) == dict.end()) {
  7.         const char* char_word = word.c_str();
  8.         for (int i = 0; i < word.length(); i++) {
  9.             if (char_word[i] == toupper(tolower(char_word[i]))) {
  10.                 if (char_word[i] == 'A' || char_word[i] == 'E' || char_word[i] == 'I' || char_word[i] == 'O' || char_word[i] == 'U') {
  11.                     upper_char++;
  12.                 }
  13.                 else {
  14.                     return false;
  15.                 }
  16.             }
  17.         }
  18.     }
  19.     if (upper_char != 1) {
  20.         return false;
  21.     }
  22.     return true;
  23. }
  24.  
  25. void task9() {
  26.     int n;
  27.     cin >> n;
  28.     unordered_set <string> dict;
  29.     for (int i = 0; i < n; i++) {
  30.         string word;
  31.         cin >> word;
  32.         dict.insert(word);
  33.     }
  34.     string sentence;
  35.     std::getline(std::cin, sentence);
  36.     cout << sentence;
  37.     istringstream stream(sentence);
  38.     string word;
  39.     int wrong_words_count = 0;
  40.     while (stream >> word) {
  41.         if (!(check_word(word, dict))) {
  42.             wrong_words_count++;
  43.         }
  44.     }
  45.     cout << wrong_words_count;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement