Monday, January 16, 2012

CodeSprint/Coin Toss


/* Enter your code here. Read input from STDIN. Print output to STDOUT */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;

public class Solution {


public static void main (String args[]) throws IOException
{

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
double solutionArray[];
int anArray[] = new int [2] ;
String Delims=" ";
String temp= br.readLine();
int counter= Integer.parseInt(temp);
String[] tempArray= new String[counter];
solutionArray= new double[counter];
for (int i = 0; i < counter; i++) {
tempArray[i]=br.readLine();
}

DecimalFormat df = new DecimalFormat("##.00");
for (int lubaluba=0;lubaluba<counter;lubaluba++)
{
String andrtemp[]=tempArray[lubaluba].split(Delims);
anArray[0]=Integer.parseInt(andrtemp[0]);
anArray[1]=Integer.parseInt(andrtemp[1]);
// System.out.print("Parsed values are"+anArray[0]+"and"+anArray[1]);
if (anArray[0]==(anArray[1])&&(counter==1))
{
String chumma="0.00";
System.out.println(chumma);
System.exit(1);
}
if(anArray[0]>anArray[1])
{
double val1= Math.pow(2, anArray[0]+1);
double val2= Math.pow(2, anArray[1]+1);
double sol=val1-val2;
solutionArray[lubaluba]=sol;
}
else if (anArray[0]==(anArray[1]))
{
double chumma=0;
solutionArray[lubaluba]=chumma;
}

}

for (int i = 0; i < solutionArray.length; i++)
{
if (solutionArray[i]==0)
{
System.out.println("0.00");
}
else
{
System.out.println(df.format(solutionArray[i]));
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
br.close();
}
}

No comments:

Post a Comment