zoukankan      html  css  js  c++  java
  • D

    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
     
     
    简单题,用java中的大数写
    注意类名Main
     
    package test;
    import java.util.Scanner;
    import java.math.BigInteger;
    public class Fib {
        static BigInteger[] num = new BigInteger[205];
        static String s;
        public static void main(String[] args){
            num[1] = new BigInteger("1");
            num[2] = new BigInteger("2");
            for(int i = 3; i <= 201; i++){               
                num[i] = num[i-1].add(num[i-2]);       
                //System.out.println(num[i]);
            }       
                            
            Scanner in = new Scanner(System.in);
            System.out.println("输入n");
            int n = in.nextInt();
            int flag = 1;
            while((n--) != 0){         
                System.out.println("输入字符串");
                if(flag == 1){
                    in.nextLine();
                    flag = 0;
                }
                s = in.nextLine();
                int len = s.length();        
                System.out.println(num[len]);               
            }
        }
    }
  • 相关阅读:
    使用jxl.jar操作Excel
    ThreadLocal学习
    ArrayList与Vector、HashMap与HashTable
    String, StringBuffer, StringBuilder比较
    ArrayList与LinkedList实现比较
    Java文件备份类
    Maven安装与更新
    Eclipse安装反编译工具JadClipse
    Linux关闭防火墙
    Hadoop简介
  • 原文地址:https://www.cnblogs.com/rain-1/p/4975999.html
Copyright © 2011-2022 走看看