环境恶劣【

P1320 压缩技术(续集版)

幻影学霸刘 @ 2019-09-21 14:52:55

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
    string a;
    int c[512],t=0;
    for(int i=0;i<512;i++)
    {
        c[i]==0;
    }
    cin>>a;
    for(int i=0;i<a.size()-1;i++)
    {
        string s;
        cin>>s;
        a+s;
    }
    bool b=a[0]-'0';
    for(int i=0;i<a.size();i++)
    {
        if(b==a[i]-'0')
        {
            for(int j=i+1;a[j]-'0'==b;j++)
            {
                c[t]++;
            }
            t++;
        }
        b++;
    }
    cout<<t<<" ";
    for(int i=0;i<t;i++)
    {
        cout<<a[i]<<" ";
    }
    return 0;
}

by 幻影学霸刘 @ 2019-09-21 15:52:14

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
    string a;
    int c[512],t=0;
    for(int i=0;i<512;i++)
    {
        c[i]=0;
    }
    cin>>a;
    for(int i=0;i<a.size()-1;i++)
    {
        string s;
        cin>>s;
        a+=s;
    }
    cout<<a.size()<<" ";
    if(a[0]=='1')
    {
        cout<<"0 ";
    }
    int cnt=1;
    bool b=a[0]-'0';
    for(int i=1;i<a.size();i++)
    {
        if(a[i]==a[i-1])
        {
            cnt++;
        }
        else
        {
            cout<<cnt<<" ";
            cnt=1;
        }
    }
    cout<<cnt;
    return 0;
}

by 幻影学霸刘 @ 2019-09-21 15:58:57

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
    string a;
    int c[512],t=0;
    for(int i=0;i<512;i++)
    {
        c[i]=0;
    }
    cin>>a;
    int as;
    for(int i=0;i<as-1;i++)
    {
        string s;
        cin>>s;
        a+=s;
    }
    cout<<a.size()<<" ";
    if(a[0]=='1')
    {
        cout<<"0 ";
    }
    int cnt=1;
    bool b=a[0]-'0';
    for(int i=1;i<a.size();i++)
    {
        if(a[i]==a[i-1])
        {
            cnt++;
        }
        else
        {
            cout<<cnt<<" ";
            cnt=1;
        }
    }
    cout<<cnt;
    return 0;
}

by T1anBooy @ 2019-09-21 21:35:23

#include <bits/stdc++.h>
using namespace std;

int num;
string a, temp;

int main() {
    while (cin >> temp)
        a += temp;
    cout << temp.length() << " ";
     if (a[0] == '1') cout << "0" << " ";
    num = 1;
    for (int j = 1; j < a.length(); j ++) {
        if (a[j] == a[j - 1]) num ++;
        if (a[j] != a[j - 1]) {
            cout << num << " ";
            num = 1;
        }
    }
    cout << num;
    return 0;
}

上一页 |