UVa - 900 Brick Wall Patterns

//java solutions

import java.io.*;
import java.util.*;
import java.math.*;

class Main
{
 

    public static void main (String args[])  // entry point from OS
    {
      new Main().Begin();
    }
    void Begin()
    {
 try
 {
 
  BigInteger b[];
 
  ArrayList abc=new ArrayList(5000);
  abc.add("0");
  abc.add("1");
  BigInteger b1=BigInteger.ZERO;
  BigInteger b2=new BigInteger("1");
  BigInteger tmp=new BigInteger("0");
  for(int i=2;i<5001;i++)
  {
   tmp=b2;
   b2=b1.add(b2);
   b1=tmp;
   abc.add(i,b2.toString());
  }
  Scanner sc=new Scanner(System.in);
int n;
       while(sc.hasNextInt())
{
n=sc.nextInt();
if(n==0) break;
System.out.println(abc.get(n+1).toString());
}
sc.close();
 }
 catch(Exception e)
 {
  System.exit(0);
 }
}
}

No comments:

Post a Comment