#include<iostream> #include<vector> #include<string> using namespace std; int main(void) { string word; cin>>word; bool alp[26]={0,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,0,1}; unsigned long long s=0, l=-1; for(int i=0,a,b,c; i<word.size()-2; i++) { a=word[i]-'a'; b=word[i+1]-'a'; c=word[i+2]-'a'; if((alp[a] && alp[b] && alp[c] )|| (!alp[a] && !alp[b] && !alp[c])) { s+=(word.size()-(i+2))*(i-l); l=i; } } cout<<s<<endl; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include<iostream> #include<vector> #include<string> using namespace std; int main(void) { string word; cin>>word; bool alp[26]={0,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,0,1}; unsigned long long s=0, l=-1; for(int i=0,a,b,c; i<word.size()-2; i++) { a=word[i]-'a'; b=word[i+1]-'a'; c=word[i+2]-'a'; if((alp[a] && alp[b] && alp[c] )|| (!alp[a] && !alp[b] && !alp[c])) { s+=(word.size()-(i+2))*(i-l); l=i; } } cout<<s<<endl; } |