P1320 压缩技术(续集版)

题目如下;

 思路:

1.核心思想:利用strcat将所有的字符串拼接在一起

2.值得注意的是 看清楚题目要求 第一个数表示连续有几个0 所以要先判断是否为0

代码如下;

#include<cstdio> 
#include<cstring>
#include<iostream>
using namespace std;
int main(){
    char s[10010],m[10010];
    int a=1,b=0;
    cin>>s;
    int n=strlen(s);
    for(int i=1;i<n;i++){
        cin>>m;
        strcat(s,m);
    }
    cout<<n<<" ";
    if(s[0]=='1')
    cout<<"0"<<" ";
     
    for(int i=0;i<strlen(s);i++)
    { if(s[i+1]==s[i])
        a++;
        else {
        cout<<a<<" ";
        a=1;    
        }
    }
    return 0;
}
/*
0001000
0001000
0001111
0001000
0001000
0001000
1111111
*/

猜你喜欢

转载自www.cnblogs.com/miao-xixixi/p/12904035.html