比赛 NOIP模拟赛1 评测结果 AAATTTTTTT
题目名称 叉叉 最终得分 30
用户昵称 sarail 运行时间 7.001 s
代码语言 C++ 内存使用 0.32 MiB
提交时间 2018-02-08 19:38:42
显示代码纯文本
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<string>
  4. #include<algorithm>
  5. #include<cstring>
  6. using namespace std;
  7. const int maxlen=100000+100;
  8. struct stack{
  9. int beg,end;
  10. }s[maxlen];
  11.  
  12. string str;
  13. int n,top,word[26],cnt,i,p;
  14.  
  15. bool cmp(stack a,stack b){
  16. return a.beg <b.beg ;
  17. }
  18. int main(){
  19. freopen("xxxx.in","r",stdin);
  20. freopen("xxxx.out","w",stdout);
  21. memset(word,-1,sizeof(word));
  22. cin>>str;
  23. cnt=top=0;
  24. n=str.length() ;
  25. for(i=0;i<n;i++){
  26. p=(int)str[i]-97;
  27. if(word[p]!=-1){
  28. s[top].beg =word[p];
  29. s[top++].end =i;
  30. word[p]=-1;
  31. }
  32. else word[p]=i;
  33. }
  34. sort(s,s+top,cmp);
  35. for(int i=1,e,b;i<top;i++){
  36. e=s[i].end;b=s[i].beg ;
  37. for(int j=i-1;j>=0;j--){
  38. if(e>s[j].end&&b<s[j].end)cnt++;
  39. }
  40. }
  41. cout<<cnt;
  42. return 0;
  43. }