补题

#include<iostream>
#include <algorithm>
using namespace std;
struct node{
    int first;
    int second;
};
node x[500005];
node y[500005];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
       int n,r,s=-1,count=0;
       cin>>n;
       for(int i=1;i<=n;i++){
           cin>>r;
           if(s==r){  //保证了x中数字的不重复
               
               if(r!=y[count].first){
                   y[++count].first = r;
                   y[++count].second = 0;
               }

//               break;
           }else{
               s=r;
               x[i].first = r;
               x[i].second = 0;
           }

       }
       for(int i=1;i<=count;i++){
           y[i].first+=1;
           y[i].second = 1;//表示被修改过了
       }
       while (true){
           
       }
    }
    return 0;
}
#include<iostream>
#include <algorithm>
#include <string>
using namespace std;
int x[500005];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
//    t = 1;
    while(t--){
       string s;
       int count = 0;
       cin>>s;
       int len = s.length();
       for(int i=0;i+3<len;i++){
           if(s[i]==s[i+1]&&s[i+1]==s[i+2]&&s[i+2]==s[i+3]&&x[i]+x[i+1]+x[i+2]+x[i+2]==0){
               x[i+1]=x[i+2]=1;
               count += 2;
               i+=4;
           }
       }
//       cout<<"len=="<<len<<endl;
       for(int i=1;i<=len-1;i++){
           if(s[i] == s[i-1] && x[i]+x[i-1] == 0){
               if((i>=2&&s[i-2]==s[i]&&x[i-2]+x[i]==0)||(i+2<len&&s[i+2]==s[i]&&x[i+2]+x[i]==0)){
                   x[i]=1;
               } else{
                   x[i-1]=1;
               }

               count++;
           }
       }
      /* for(int i =0;i<len;i++){
           cout<<x[i]<<" ";
       }
       cout<<endl;*/
        for (int j = 1; j <= len-2 ; ++j) {
            if(s[j-1] == s[j+1] && x[j-1]+x[j+1] == 0){
                x[j-1] = 1;
                count++;
            }
        }
        for(int i = 0;i<len;i++){
            x[i] = 0;
        }
        cout<<count<<endl;
       }
    return 0;
}
原文地址:https://www.cnblogs.com/Acapplella/p/14214325.html