zoukankan      html  css  js  c++  java
  • 找规律

    1.

    1 3
    1 1 1 3
    3 1 1 3
    1 3 2 1 1 3
    1 1 1 3 1 2 2 1 1 3
    3 1 1 3 1 1 2 2 2 1 1 3
    ……

    第一行是默认的1 3;

    从第二行开始 一个1 一个3 所以是1 1 1 3

    第三行 三个1 一个三 所以是3 1 1 3

    第四行 一个3 两个1 一个3 所以是1 3 2 1 1 3

    .。。。。。。。

     1 #include<iostream>
     2 #include<string.h>
     3 using namespace std;
     4 int main()
     5 {
     6     int num = 0;//重复次数
     7     int a_column = 0;//a数组的列数
     8     int a[10][50];//找规律的数组
     9     memset(a,0,sizeof(int)*500);//把数组归零
    10     a[0][0] = 1;//数组默认第一行是1 3
    11     a[0][1] = 3;
    12     int flag;//标记当前数
    13     for(int i = 0 ; i < 9 ; i ++)
    14     {
    15         flag = a[i][0];
    16         for(int j = 0 ; j < 49 ; j++)
    17         {
    18             if(a[i][j]!=0)
    19             {
    20                 if(a[i][j]==flag)num++;//如果a里面一行有多个跟flag一样的数,num++
    21                 else
    22                 {
    23                     flag = a[i][j];
    24                     a[i+1][a_column] = num;//数组下一行第一个数为num数
    25                     a_column++;
    26                     a[i+1][a_column] = a[i][j-1];//数组下一行第二个数为flag
    27                     a_column++;
    28                     num = 1;
    29                 }
    30             }
    31             else        //如果为0 代表这行读完了
    32             {
    33                 a[i+1][a_column] = num;
    34                 a_column++;
    35                 a[i+1][a_column] = a[i][j-1];
    36                 a_column++;
    37                 j = 50;//为了结束这次j循环
    38             }
    39         }
    40         a_column = 0;
    41         num = 0;
    42     }
    43     for(int i = 0 ; i < 9 ; i++ )
    44     {
    45         for(int j = 0 ; j < 49 ; j++ )
    46         {
    47             if(a[i][j]!=0)cout<<a[i][j] <<" ";
    48         }
    49         cout<<endl;
    50     }
    51 }
  • 相关阅读:
    宝藏 题解
    Xorequ 题解
    2020.12.26 模拟赛 题解
    数据结构 100 题 1~10 线段树
    关于模拟退火
    诗意狗 题解
    Keyboading 思路
    体育成绩统计/ Score
    【(抄的)题解】P5686 [CSP-SJX2019]和积和
    【笔记】简单博弈
  • 原文地址:https://www.cnblogs.com/Duskcl/p/3943873.html
Copyright © 2011-2022 走看看