D - 1sting(相当于斐波那契数列,用大数写)
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]); } } }
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步