2399: 【入门】【P1320】压缩技术(续集版)

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:33 解决:11

题目描述

设某汉字由 lns="http://www.w3.org/1998/Math/MathML">× 的 lns="http://www.w3.org/1998/Math/MathML">0 和 lns="http://www.w3.org/1998/Math/MathML">1 的点阵图案组成。

我们依照以下规则生成压缩码。连续一组数值:从汉字点阵图案的第一行第一个符号开始计算,按书写顺序从左到右,由上至下。第一个数表示连续有几个 lns="http://www.w3.org/1998/Math/MathML">0,第二个数表示接下来连续有几个 lns="http://www.w3.org/1998/Math/MathML">1,第三个数再接下来连续有几个 lns="http://www.w3.org/1998/Math/MathML">0,第四个数接着连续几个 lns="http://www.w3.org/1998/Math/MathML">1,以此类推……

例如: 以下汉字点阵图案:

0001000 0001000 0001111 0001000 0001000 0001000 1111111 

对应的压缩码是: lns="http://www.w3.org/1998/Math/MathML">7 3 1 6 1 6 4 3 1 6 1 6 1 3 7 (第一个数是 lns="http://www.w3.org/1998/Math/MathML"> ,其余各位表示交替表示0和1 的个数,压缩码保证 lns="http://www.w3.org/1998/Math/MathML">×= 交替的各位数之和)

输入

汉字点阵图(点阵符号之间不留空格)。

输出

输出一行,压缩码。

样例输入 复制

0001000
0001000
0001111
0001000
0001000
0001000
1111111

样例输出 复制

7 3 1 6 1 6 4 3 1 6 1 6 1 3 7

提示

数据保证,lns="http://www.w3.org/1998/Math/MathML">3200

#include<iostream>
#include<cmath>
using namespace std;
char c,last='0';
int t,a[40010],k=1;

int main(){
    while(cin>>c){
 	    t++;
 	    if(c==last)
 		    a[k]++; //数组当前的值+1
 	    else {
 		    a[++k]++; //数组下标后移1位,并让其值+1
 		    last=c; //更新"上一个"字符	        
 	    }
    }
    cout<<sqrt(t);  //相当于n
    for(int i=1;i<=k;i++)
        cout<<" "<<a[i];
    return 0;
}