View Code of Problem 108

import  java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int t = scanner.nextInt();
		for(int i=0; i<t; i++) {
			String s = scanner.next();
			int x = s.length();
			if(x == 1) {
				System.out.println(1);
			}else if(x == 2) {
				System.out.println(2);
			}else {
				long[] arr = new long[x];
				arr[0] = 1;
				arr[1] = 2;
				for(int j=2; j<x; j++) {
					arr[j] = arr[j-1]+arr[j-2];
				}
				System.out.println(arr[x-1]);
			}
		}
	}
}

Double click to view unformatted code.


Back to problem 108