华为上机试题:数字问题.

摘要:给定一个数字序列11,要求第二行的序列是21,第三行是1211.每一行都是对上一行的描述.第四行是111221,即(1个1.1个2,2个1).求出第1到第11行的情况.

#include "stdafx.h"
#define Number 100
int Find(int *A,int *B,int bound)
{
    int x;
    int i = 0,j=0,count = 0,k = 0;;
    while(i<=bound)
    {
     x = A[i];
     count = 0;
    while(x == A[i])
    {
        i++;
        count++;
    }

    B[j++] = count;
    B[j++] = x;
    }
    while(k<=j-1)
        printf("%d ",B[k++]);
        puts("\n");
    return j-1;
}
int _tmain(int argc, _TCHAR* argv[])
{
    int A[Number] = {0},B[Number] = {0};
    int *a = A,*b = B,*c;
    int bound = 0;
    A[0] = 1;
    for (int i = 0;i<=10;i++)
    {
        bound = Find(a,b,bound);
        c = a;
        a = b;
        b = c;
    }
    return 0;
}

华为上机试题:数字问题._第1张图片

你可能感兴趣的:(华为上机试题:数字问题.)