#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <string.h>
using namespace std;
inline bool is_vowel(char c){
return c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='y';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// oczyt danych wejściowych
char input[200002];
cin.getline(input, sizeof(input));
/** Licznik kolejnych samogłosek >0 lub spółgłosek <0 */
int res=0;
int p=0;
int64_t sum=0;
for(int i=0;input[i]!='\0';++i) {
if(is_vowel(input[i])) {
if(res<0) res=0; // jeżeli wcześniej były spółgłoski, to zerujemy
++res; // zliczamy tą
} else {
if(res>0) res=0; // jeżeli wcześniej były samogłoski, to zerujemy
--res; // zliczamy tą
}
if(res>=3 || res<=-3) { // jeżeli są trzy lub więcej spółgłoski lub samogłoski pod rząd, to liczymy możliwości
p=i-1;
}
sum+=p;
}
// cout<<strlen(input)<<endl;
cout<<sum<<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 | #include <iostream> #include <map> #include <vector> #include <string> #include <string.h> using namespace std; inline bool is_vowel(char c){ return c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='y'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // oczyt danych wejściowych char input[200002]; cin.getline(input, sizeof(input)); /** Licznik kolejnych samogłosek >0 lub spółgłosek <0 */ int res=0; int p=0; int64_t sum=0; for(int i=0;input[i]!='\0';++i) { if(is_vowel(input[i])) { if(res<0) res=0; // jeżeli wcześniej były spółgłoski, to zerujemy ++res; // zliczamy tą } else { if(res>0) res=0; // jeżeli wcześniej były samogłoski, to zerujemy --res; // zliczamy tą } if(res>=3 || res<=-3) { // jeżeli są trzy lub więcej spółgłoski lub samogłoski pod rząd, to liczymy możliwości p=i-1; } sum+=p; } // cout<<strlen(input)<<endl; cout<<sum<<endl; return 0; } |
English