Advertisement
Guest User

5

a guest
May 19th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<vector>
  4.  
  5. using namespace std;
  6.  
  7. typedef vector < string > strvec;
  8.  
  9. strvec get_all_words(string text){
  10.     strvec result;
  11.     string temp;
  12.     for (int i = 0; i < text.size(); ++i){
  13.         if (isalnum(text[i])){
  14.             temp += text[i];
  15.         } else {
  16.             if (!temp.empty()){
  17.                 result.push_back(temp);
  18.                 temp.clear();
  19.             }
  20.         }
  21.     }
  22.     return result;
  23. }
  24.  
  25. bool good(char ch){
  26.     ch = tolower(ch);
  27.     return ch == 'e' || ch == 'u' || ch == 'i' || ch == 'o' || ch == 'a' || ch == 'y';
  28. }
  29. bool check(const string &word){
  30.     return good(*word.rbegin());
  31. }
  32.  
  33. bool isnum(const string &word){
  34.     for (int i = 0; i < word.size(); ++i){
  35.         if (isalpha(word[i])){
  36.             return false;
  37.         }
  38.     }
  39.     return true;
  40. }
  41.  
  42. int main(){
  43.  
  44.     ifstream in("input.txt");
  45.     ofstream out("output.txt");
  46.  
  47.     string all;
  48.  
  49.     string line;
  50.     while (getline(in, line)){
  51.         all += line + "\n";
  52.         out << line << "\n";
  53.     }
  54.  
  55.     strvec words = get_all_words(all),
  56.            small_words;
  57.     int cnt = 0;
  58.     for (int i = 0; i < words.size();){
  59.         cnt += check(words[i]);
  60.         if (words[i].size() < 5){
  61.             small_words.push_back(words[i]);
  62.         }
  63.         if (!isnum(words[i])){
  64.             words.erase(words.begin() + i);
  65.         } else {
  66.             ++i;
  67.         }
  68.     }
  69.  
  70.     cout << cnt << "\n"
  71.          << "Numbers:\n";
  72.     for (int i = 0; i < words.size(); ++i){
  73.         cout << words[i] << " ";
  74.     }
  75.     cout << "\n"
  76.          << "Small words:\n";
  77.     for (int i = 0; i < small_words.size(); ++i){
  78.         cout << small_words[i] << " ";
  79.     }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement