#include <stdio.h> #include <cstring> #include <cassert> #include <algorithm> #include <vector> char samo[] = {'a','e','i','o','u','y'}; bool isSamo(const char c) { for (int i =0;i<6;i++) if(c == samo[i]) return true; return false; } int main() { std::vector<std::pair<int,int>> positions; char buf[200005]; scanf("%s",buf); long long res =0; positions.reserve(strlen(buf)); bool samo = isSamo(buf[0]); long long n=strlen(buf); int begin=0, end =0; for (int i =1;i<n;i++) { bool nSamo = isSamo(buf[i]); if(nSamo == samo) { end++; continue; } else { samo=nSamo; if(end-begin>=2) positions.push_back(std::make_pair(begin,end)); begin=end=i; } } if(end-begin>=2) positions.push_back(std::make_pair(begin,end)); long long all = (n*(n+1)/2LL); if(positions.size() == 0) { printf("0\n"); return 0; } long long dobre = 0; long long beginLen = positions[0].first; dobre = (beginLen*(beginLen+1LL))/2LL; for (int i=0;i<positions.size();i++) { long long beginOk = positions[i].second + 1; long long endOk = (i==positions.size()-1) ? n-1 : positions[i+1].first -1; long long okLen = endOk - beginOk + 1; long long wrongLen = positions[i].second - positions[i].first + 1; if(okLen > 0) dobre += (okLen*(okLen+1LL)) / 2LL; dobre += wrongLen + wrongLen - 1LL; dobre += 2LL* okLen; long long prevBeginOk = (i==0) ? 0 : positions[i-1].second-1; long long prevEndOk = positions[i].first -1; long long prevOkLen = prevEndOk - prevBeginOk + 1; dobre += 2*prevOkLen; } printf("%lld\n",all-dobre); 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 | #include <stdio.h> #include <cstring> #include <cassert> #include <algorithm> #include <vector> char samo[] = {'a','e','i','o','u','y'}; bool isSamo(const char c) { for (int i =0;i<6;i++) if(c == samo[i]) return true; return false; } int main() { std::vector<std::pair<int,int>> positions; char buf[200005]; scanf("%s",buf); long long res =0; positions.reserve(strlen(buf)); bool samo = isSamo(buf[0]); long long n=strlen(buf); int begin=0, end =0; for (int i =1;i<n;i++) { bool nSamo = isSamo(buf[i]); if(nSamo == samo) { end++; continue; } else { samo=nSamo; if(end-begin>=2) positions.push_back(std::make_pair(begin,end)); begin=end=i; } } if(end-begin>=2) positions.push_back(std::make_pair(begin,end)); long long all = (n*(n+1)/2LL); if(positions.size() == 0) { printf("0\n"); return 0; } long long dobre = 0; long long beginLen = positions[0].first; dobre = (beginLen*(beginLen+1LL))/2LL; for (int i=0;i<positions.size();i++) { long long beginOk = positions[i].second + 1; long long endOk = (i==positions.size()-1) ? n-1 : positions[i+1].first -1; long long okLen = endOk - beginOk + 1; long long wrongLen = positions[i].second - positions[i].first + 1; if(okLen > 0) dobre += (okLen*(okLen+1LL)) / 2LL; dobre += wrongLen + wrongLen - 1LL; dobre += 2LL* okLen; long long prevBeginOk = (i==0) ? 0 : positions[i-1].second-1; long long prevEndOk = positions[i].first -1; long long prevOkLen = prevEndOk - prevBeginOk + 1; dobre += 2*prevOkLen; } printf("%lld\n",all-dobre); return 0; } |