zoukankan      html  css  js  c++  java
  • 1sting

    ///题解 : 找规律,大菲波数
     
    Problem Description
    You will be given a string which only contains ‘1’; You can merge two adjacent ‘1’ to be ‘2’, or leave the ‘1’ there. Surly, you may get many different results. For example, given 1111 , you can get 1111, 121, 112,211,22. Now, your work is to find the total number of result you can get.
     
    Input
    The first line is a number n refers to the number of test cases. Then n lines follows, each line has a string made up of ‘1’ . The maximum length of the sequence is 200.
     
    Output
    The output contain n lines, each line output the number of result you can get .
     
    Sample Input
    3 1 11 11111
     
    Sample Output
    1 2 8
     1 #include <stdio.h>
     2 #include<iostream>
     3 #include<cstring>
     4 #define N 1001
     5 using namespace std;
     6 char a[N][N];
     7 int main()
     8 {
     9     memset(a,'0',sizeof(a)); 
    10     a[1][0]='1';
    11     a[2][0]='2';
    12     int i,j,d=1;
    13     for(i=3;i<N;i++)//i控制行数 
    14     {
    15         d++;   //控制列数 
    16         int c=0,s;  //c为进位指数的初值 
    17         for(j=0;j<=d;j++)      //j控制列数的循环
    18         {
    19             s=a[i-1][j]-'0'+a[i-2][j]-'0'+c;
    20             c=s/10; //满十进位
    21             a[i][j]=s%10+'0';   //满十的话,将舍位
    22         }
    23 
    24     }
    25     int t;
    26     char s[1000];
    27     scanf("%d",&t);
    28     while(t--)
    29     {
    30         scanf("%s",s);
    31         int n=strlen(s);
    32         int k=N-1;
    33         while(k--)
    34         {
    35             if(a[n][k]!='0') break;    //反向搜索第一个不为‘0’的字符
    36         }
    37         for(i=k;i>=0;i--)  //从后往前输出
    38             printf("%c",a[n][i]);
    39        printf("
    ");
    40     }
    41     return 0;
    42 }
    View Code
  • 相关阅读:
    Prototype源码浅析——String部分(四)之补充
    改造alert的引发的争论【基本类型与引用类型】
    Eclipse rcp 窗口激活
    Eclipse statusLine 加入进度信息
    线的匹配
    python 文本搜索
    Eclipse rcp 编辑器行号显示
    CDT重建索引
    Eclipse rcp 数据存储
    CTabFolder 最大最小化
  • 原文地址:https://www.cnblogs.com/awsent/p/4266172.html
Copyright © 2011-2022 走看看