P1320 压缩技术(续集版)

题目描述

设某汉字由N X N的0和1的点阵图案组成,如下图。我们依照以下规则生成压缩码。连续一组数值:从汉字点阵图案的第一行第一个符号开始计算,按书写顺序从上到下,由左到右。第一个数表示连续有几个0,第二个数表示接下来连续有几个1,第三个数再接下来连续有几个0,第四个数接着连续几个1,以此类推。。。

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

0001000

0001000

0001111

0001000

0001000

0001000

1111111

对应的压缩码是: 7 3 1 6 1 6 4 3 1 6 1 6 1 3 7 (第一个数是N ,其余各位表示交替表示0和1 的个数,压缩码保证 N X N=交替的各位数之和)

输入输出格式

输入格式:

汉字点阵图(点阵符号之间不留空格)。(3<=N<=200)

输出格式:

一行,压缩码。

输入输出样例

输入样例#1:
0001000
0001000
0001111
0001000
0001000
0001000
1111111
输出样例#1:
7 3 1 6 1 6 4 3 1 6 1 6 1 3 7
#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<cmath>
using namespace std;
char a[300][300],c,last='0';
int t=0,n,tot;
int main()
{
    cin>>a[0];
    n=strlen(a[0]);
    for(int i=1;i<n;i++)    cin>>a[i];
    printf("%d ",n);    
    for(int j=0;j<n;j++)
    {    
        for(int i=0;i<n;i++)
        {
            if(a[j][i]==last) tot++;
            else {
                printf("%d ",tot);
                last=a[j][i],tot=1;
            }
        }
    }
    cout<<tot;
    return 0;
}
原文地址:https://www.cnblogs.com/CLGYPYJ/p/7347808.html