#include <iostream> #include <cmath> #include<algorithm> using namespace std; int samogloska(char c) { if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c=='u' || c == 'y') { return 1; } else { return -1; } } bool trudny(string s) { if(s.size() != 3) { cout << "Cos skopales\n"; } if(abs(samogloska(s[0]) + samogloska(s[1]) + samogloska(s[2])) == 3) { return true; } return false; } long long int oblicz(long long int a, long long int b) { return a + b + a*b + 1; } int main() { ios_base::sync_with_stdio(0); string s; unsigned long long int wynik = 0, last = 0; cin>>s; for(int i = 2; i < s.size(); i++) { string trzy = s.substr(i-2,3); if(trudny(trzy)) { long long int a,b; a = i - 2 - last; b = s.size() - i - 1; wynik += oblicz(a,b); last = i - 1; } } cout << wynik <<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 | #include <iostream> #include <cmath> #include<algorithm> using namespace std; int samogloska(char c) { if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c=='u' || c == 'y') { return 1; } else { return -1; } } bool trudny(string s) { if(s.size() != 3) { cout << "Cos skopales\n"; } if(abs(samogloska(s[0]) + samogloska(s[1]) + samogloska(s[2])) == 3) { return true; } return false; } long long int oblicz(long long int a, long long int b) { return a + b + a*b + 1; } int main() { ios_base::sync_with_stdio(0); string s; unsigned long long int wynik = 0, last = 0; cin>>s; for(int i = 2; i < s.size(); i++) { string trzy = s.substr(i-2,3); if(trudny(trzy)) { long long int a,b; a = i - 2 - last; b = s.size() - i - 1; wynik += oblicz(a,b); last = i - 1; } } cout << wynik <<endl; return 0; } |