#include <string> #include <iostream> using namespace std; static string vowels = "aeiouy"; void plot_coded(bool *x, size_t len) { for(int i = 0 ; i < len;++i) { cout<<x[i]; } } size_t substring(size_t n) { { return (n*(n-1))-((1+(n-2))*(n-2)/2)+1; } } int main(int argc,char** argv) { string input; cin>>input; size_t char_count = input.length(); if(char_count < 3) { cout<<0; return 0; } bool *coded_input = new bool[char_count]; for(int i = 0 ; i < char_count;++i) { coded_input[i] = 0; for(char& v : vowels) { if(input[i] == v) { coded_input[i] = 1; } } } //plot_coded(coded_input,char_count); size_t result = substring(char_count); size_t last_difficult = 0; bool long_sequence = false; for(int i = 3 ; i <= char_count;++i) { static bool last1 = coded_input[0]; static bool last2 = coded_input[1]; static bool last3 = coded_input[2]; if(last1 == last2 && last2 == last3) { if(long_sequence == false) { result-= substring(i-1-last_difficult); long_sequence = true; } result-= 2; last_difficult = i - 2; } else { long_sequence = false; } last1 = last2; last2 = last3; last3 = coded_input[i]; } if(long_sequence == false) { result-= substring(char_count-1-last_difficult); } cout<<result; 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | #include <string> #include <iostream> using namespace std; static string vowels = "aeiouy"; void plot_coded(bool *x, size_t len) { for(int i = 0 ; i < len;++i) { cout<<x[i]; } } size_t substring(size_t n) { { return (n*(n-1))-((1+(n-2))*(n-2)/2)+1; } } int main(int argc,char** argv) { string input; cin>>input; size_t char_count = input.length(); if(char_count < 3) { cout<<0; return 0; } bool *coded_input = new bool[char_count]; for(int i = 0 ; i < char_count;++i) { coded_input[i] = 0; for(char& v : vowels) { if(input[i] == v) { coded_input[i] = 1; } } } //plot_coded(coded_input,char_count); size_t result = substring(char_count); size_t last_difficult = 0; bool long_sequence = false; for(int i = 3 ; i <= char_count;++i) { static bool last1 = coded_input[0]; static bool last2 = coded_input[1]; static bool last3 = coded_input[2]; if(last1 == last2 && last2 == last3) { if(long_sequence == false) { result-= substring(i-1-last_difficult); long_sequence = true; } result-= 2; last_difficult = i - 2; } else { long_sequence = false; } last1 = last2; last2 = last3; last3 = coded_input[i]; } if(long_sequence == false) { result-= substring(char_count-1-last_difficult); } cout<<result; return 0; } |