zoukankan      html  css  js  c++  java
  • C Good String (模拟 ) Codeforces Round #560 (Div. 3)

    Let's call (yet again) a string good if its length is even, and every character in odd position of this string is different from the next character (the first character is different from the second, the third is different from the fourth, and so on). For example, the strings good, string and xyyx are good strings, and the strings bad, aa and aabc are not good. Note that the empty string is considered good.

    You are given a string ss, you have to delete minimum number of characters from this string so that it becomes good.

    Input

    The first line contains one integer nn (1n21051≤n≤2⋅105) — the number of characters in ss.

    The second line contains the string ss, consisting of exactly nn lowercase Latin letters.

    Output

    In the first line, print one integer kk (0kn0≤k≤n) — the minimum number of characters you have to delete from ss to make it good.

    In the second line, print the resulting string ss. If it is empty, you may leave the second line blank, or not print it at all.

    Examples

    Input
    4
    good
    
    Output
    0
    good
    
    Input
    4
    aabc
    
    Output
    2
    ab
    
    Input
    3
    aaa
    
    Output
    3
    

     

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <map>
    #include <vector>
    #include <set>
    #include <queue>
    #include <stack>
    #include <cmath>
    //
    #define lson rt<<1, l, m
    #define rson rt<<1|1, m+1, r
    //
    #define fi      first
    #define se      second
    #define pb      push_back
    #define pq      priority_queue<int>
    #define ok      return 0;
    #define os(str) cout<<string(str)<<endl;
    #define gcd __gcd
    #define mem(s,t) memset(s,t,sizeof(s))
    #define debug(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
    #define debug1(a,n) for(int i=1;i<=n;i++) cout<<a[i]<<" ";  cout<<endl;
    #define debug02(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" ";   cout<<endl; }
    #define read11(a,k) for (int i = 1; i <= (int)(k); i++)  {cin>>a[i];}
    #define read02(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cin>>a[i][j] ; }
    #define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);
    
    using namespace std;
    inline void NO()
    {
        cout<<"NO"<<endl;
    }
    inline void YES()
    {
        cout<<"YES"<<endl;
    }
    const  int  mxn = 2e5+10;
    #define oi(x)   cout<<x<<endl;
    #define rep(k)    for (int i=0;i<n;i++)
    #define rep1(j,k) for (int i=j;i<=k;  i++)
    #define per(j,k)  for (int i=j;i>=k; i--)
    #define per(k)    for (int i=k-1;i>=0;i--)
    string str,ch;
    int n;
    int main()
    {
        int n;
        while(cin>>n)
        {
            ch="";
            cin>>str;
                    int j;
            for(int i=0; i<n;)
            {
                if( str[i]!=str[i+1] && i+1<n )
                {
                    ch+=str[i];
                    ch+=str[i+1];
                    i+=2;
                }
                else
                {
    
                    for(j=i+2;j<n && j<n;)
                    {
                        if(str[i]!=str[j])
                        {
                            ch+=str[i];
                            ch+=str[j];
                            i=j+1;
                            j++;
                            break;
                        }
                        else
                            j++;
                    }
                    i=j;
                }
            }
            cout<<str.size()-ch.size()<<endl;
            cout<<ch<<endl;
        }
        ok;
    }
    所遇皆星河
  • 相关阅读:
    88、使用tensorboard进行可视化学习,查看具体使用时间,训练轮数,使用内存大小
    88、展示Tensorflow计算图上每个节点的基本信息以及运行时消耗的时间和空间
    关于实时监听输入框的值变化
    再谈javascript函数节流
    HTML5离线缓存Manifest
    javascript判断浏览器支持CSS3属性
    关于移动web开发过程中的”点透“问题
    跨域解决方案之HTML5 postMessage
    最精简的金额格式化
    Grunt usemin前端自动化打包流程
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/11621443.html
Copyright © 2011-2022 走看看