比赛 |
NOIP模拟赛1 |
评测结果 |
AAATTTTTTT |
题目名称 |
叉叉 |
最终得分 |
30 |
用户昵称 |
sarail |
运行时间 |
7.001 s |
代码语言 |
C++ |
内存使用 |
0.32 MiB |
提交时间 |
2018-02-08 19:38:42 |
显示代码纯文本
- #include<iostream>
- #include<cstdio>
- #include<string>
- #include<algorithm>
- #include<cstring>
- using namespace std;
- const int maxlen=100000+100;
- struct stack{
- int beg,end;
- }s[maxlen];
-
- string str;
- int n,top,word[26],cnt,i,p;
-
- bool cmp(stack a,stack b){
- return a.beg <b.beg ;
- }
- int main(){
- freopen("xxxx.in","r",stdin);
- freopen("xxxx.out","w",stdout);
- memset(word,-1,sizeof(word));
- cin>>str;
- cnt=top=0;
- n=str.length() ;
- for(i=0;i<n;i++){
-
- p=(int)str[i]-97;
-
- if(word[p]!=-1){
- s[top].beg =word[p];
- s[top++].end =i;
- word[p]=-1;
- }
- else word[p]=i;
- }
- sort(s,s+top,cmp);
- for(int i=1,e,b;i<top;i++){
- e=s[i].end;b=s[i].beg ;
- for(int j=i-1;j>=0;j--){
- if(e>s[j].end&&b<s[j].end)cnt++;
- }
- }
- cout<<cnt;
- return 0;
-
-
-
- }