//
// pol.cpp
// Jezyk polski
//
#include <iostream>
#include <string>
#include <set>
using namespace std;
bool isDifficultWord(const string::iterator &begin, const string::iterator &end, const set<char> &charset){
string::iterator currentIt {begin + 1};
string::iterator prevIt {begin};
while(currentIt != end){
if(charset.count(*currentIt) == charset.count(*prevIt)){
currentIt++;
prevIt++;
}else{
return false;
}
}
return true;
}
int main(int argc, const char * argv[]) {
string inputText {"aaabbb"};
cin >> inputText;
set<char> charset {'a','e','i','o','u','y'};
size_t wordsCount = 0;
int difficultWordLenght = 3;
if(inputText.length() >= difficultWordLenght){
string::iterator difficultWordStartIt {inputText.begin()};
string::iterator difficultWordEndIt {inputText.begin() + difficultWordLenght - 1};
int position = 0;
size_t lenghtLeft = inputText.length();
while(difficultWordEndIt != inputText.end()){
if(isDifficultWord(difficultWordStartIt, difficultWordEndIt + 1, charset)){
wordsCount += 1 + position;
if(lenghtLeft - difficultWordLenght > 0){
wordsCount += ((lenghtLeft - difficultWordLenght) * (position + 1));
}
position = 0;
}else{
position++;
}
difficultWordStartIt++;
difficultWordEndIt++;
lenghtLeft--;
}
}
cout << wordsCount << endl;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | // // pol.cpp // Jezyk polski // #include <iostream> #include <string> #include <set> using namespace std; bool isDifficultWord(const string::iterator &begin, const string::iterator &end, const set<char> &charset){ string::iterator currentIt {begin + 1}; string::iterator prevIt {begin}; while(currentIt != end){ if(charset.count(*currentIt) == charset.count(*prevIt)){ currentIt++; prevIt++; }else{ return false; } } return true; } int main(int argc, const char * argv[]) { string inputText {"aaabbb"}; cin >> inputText; set<char> charset {'a','e','i','o','u','y'}; size_t wordsCount = 0; int difficultWordLenght = 3; if(inputText.length() >= difficultWordLenght){ string::iterator difficultWordStartIt {inputText.begin()}; string::iterator difficultWordEndIt {inputText.begin() + difficultWordLenght - 1}; int position = 0; size_t lenghtLeft = inputText.length(); while(difficultWordEndIt != inputText.end()){ if(isDifficultWord(difficultWordStartIt, difficultWordEndIt + 1, charset)){ wordsCount += 1 + position; if(lenghtLeft - difficultWordLenght > 0){ wordsCount += ((lenghtLeft - difficultWordLenght) * (position + 1)); } position = 0; }else{ position++; } difficultWordStartIt++; difficultWordEndIt++; lenghtLeft--; } } cout << wordsCount << endl; return 0; } |
English