#include <stdio.h> #include <iostream> #include <string.h> #include <string> using namespace std;; void init_map(char* the_map) { for(char c='a'; c <= 'z'; c++) { if(('a' == c) || ('o' == c) || ('u' == c) || ('y' == c) || ('e' == c) || ('i' == c)) { the_map[c] = 'a'; } else { the_map[c] = 'b'; } } } char map_char(char* the_map, char c) { return the_map[c]; } void convert_to_ab(const char* from, char* to, size_t size) { char mapping['z' + 1]; init_map(mapping); int i = 0; for(i = 0; i < size; i++) { to[i] = map_char(mapping, from[i]); } } const char* get_next_position(const char* str, size_t size_of_str, size_t size_of_pattern) { int idx = 0; while(idx + size_of_pattern <= size_of_str) { bool match = true; for(int i = 0; i < size_of_pattern - 1; i ++ ) { if(str[idx + i] != str[idx + i + 1]) { match = false; break; } } if(match == true) { return str + idx; } idx ++; } return 0; } long long compute(const char* str) { int len = strlen(str); char* new_str = new char[len]; convert_to_ab(str, new_str, len); const char* start = new_str; const char* next = new_str; long long result = 0; int next_len = len; while (next != (char*)0) { next_len = len - (start - new_str); next = get_next_position(start, next_len, 3); if(next != (char*)0) { result += (next - start + 1)*(next_len - (next - start + 2)); start = next + 1; } } delete[] new_str; return result; } int main(int argc, char* argv[]) { string str; getline(std::cin, str); printf("%lld", compute(str.c_str())); }
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 | #include <stdio.h> #include <iostream> #include <string.h> #include <string> using namespace std;; void init_map(char* the_map) { for(char c='a'; c <= 'z'; c++) { if(('a' == c) || ('o' == c) || ('u' == c) || ('y' == c) || ('e' == c) || ('i' == c)) { the_map[c] = 'a'; } else { the_map[c] = 'b'; } } } char map_char(char* the_map, char c) { return the_map[c]; } void convert_to_ab(const char* from, char* to, size_t size) { char mapping['z' + 1]; init_map(mapping); int i = 0; for(i = 0; i < size; i++) { to[i] = map_char(mapping, from[i]); } } const char* get_next_position(const char* str, size_t size_of_str, size_t size_of_pattern) { int idx = 0; while(idx + size_of_pattern <= size_of_str) { bool match = true; for(int i = 0; i < size_of_pattern - 1; i ++ ) { if(str[idx + i] != str[idx + i + 1]) { match = false; break; } } if(match == true) { return str + idx; } idx ++; } return 0; } long long compute(const char* str) { int len = strlen(str); char* new_str = new char[len]; convert_to_ab(str, new_str, len); const char* start = new_str; const char* next = new_str; long long result = 0; int next_len = len; while (next != (char*)0) { next_len = len - (start - new_str); next = get_next_position(start, next_len, 3); if(next != (char*)0) { result += (next - start + 1)*(next_len - (next - start + 2)); start = next + 1; } } delete[] new_str; return result; } int main(int argc, char* argv[]) { string str; getline(std::cin, str); printf("%lld", compute(str.c_str())); } |