Pages

1/19/2014

UVA 10195 Solution

import java.util.Scanner;


class Main {

/**UVA java solution to  10195
* @param args
*/
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);

double[]  side = new double[3];
while(sc.hasNext()) {
for (int i =0; i<3 ;i++) {
side[i] = sc.nextDouble();
}

double d = 0.5 *  (side[0] + side[1] + side [2]);
if(d!=0) {
double area =  Math.sqrt(d* (d-side[0]) * (d-side[1]) * (d-side[2]));
double rad = area / d;
System.out.printf("The radius of the round table is: %.3f\n", rad);
}
else
//if (rad == Nan) System.out.println();;
System.out.printf("The radius of the round table is: 0.000\n");
}
}

}

UVA 12250 solution

import java.util.Scanner;

public class Main {

/**
* @param args
* UVA 12250 java solution
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int ctr =0;
String m= new String();
String lan = new String();
while (!(m=sc.nextLine()).equalsIgnoreCase("#")){
ctr++;
if(m.equalsIgnoreCase("HELLO"))
lan = "ENGLISH";
else if(m.equalsIgnoreCase("HOLA"))
lan = "SPANISH";
else if(m.equalsIgnoreCase("HALLO"))
lan = "GERMAN";
else if(m.equalsIgnoreCase("BONJOUR"))
lan = "FRENCH";
else if(m.equalsIgnoreCase("CIAO"))
lan = "ITALIAN";
else if(m.equalsIgnoreCase("ZDRAVSTVUJTE"))
lan = "RUSSIAN";
else
lan = "UNKNOWN";

System.out.printf("Case %d : %s\n",ctr,lan);
}

}

}

UVA 11364 java solution

import java.util.Arrays;
import java.util.Scanner;

public class Main {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
boolean flag = true;
int tc = sc.nextInt();
for (int i = 0; i<tc; i++) {
int no = sc.nextInt();
int [] arr = new int [no];
for (int j =0 ; j < no ;j++) arr[j] = sc.nextInt();
Arrays.sort(arr);
System.out.println(2*(arr[no-1] - arr[0]));

}
}

}

UVA 11850 Java Solution

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
import java.util.Arrays;
   
    import java.util.Scanner;
   
   
    public class Main {
        public static void main(String[] args) throws IOException {
            //Scanner sc =new Scanner(System.in);
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            //StringBuilder sb = new StringBuilder();
StringBuffer sbr = new StringBuffer("");
            String m = "";
            //boolean flag=true;
int tc = Integer.parseInt(br.readLine());
while(tc!=0)
{
boolean possible = true;
//int tc = Integer.parseInt(br.readLine());
int [] stations = new int[tc];
for (int i = 0; i< tc; i++) {
stations[i]= Integer.parseInt(br.readLine());
}
Arrays.sort(stations);
if (tc<7) possible = false;
else{
if (stations[0] > 200) possible = false;
else if ( 1422 - stations[tc-1] > 100) possible = false;
else {
int tmp = stations[0];
for (int idx2 =1; idx2<tc; idx2++) {
if (stations[idx2] - tmp > 200)  possible = false;
else {
tmp = stations[idx2];
}
}
}
}
if (!possible) sbr.append("IMPOSSIBLE" + "\n");
else {
sbr.append("POSSIBLE\n");
}
tc = Integer.parseInt(br.readLine());
}
System.out.print(sbr);
        }
        }

UVA 10252 Common Permutation Java solution

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

public class Main {

/**
* @param args
* @throws IOException
* UVA 10252 - Common permutation solution
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader bReader = new   BufferedReader(new InputStreamReader(System.in));
StringBuffer sbr = new StringBuffer("");

String m;
while ((m=bReader.readLine())!=null) {
int [] c1 = new int[26];
int [] c2 = new int[26];
int [] cres = new int[26];

for (int i=0 ; i< m.length(); i++) {
if(m.charAt(i)>='a' && m.charAt(i)<='z' ){
                    c1[m.charAt(i)-97]++;
}
}
m=bReader.readLine();
for (int i=0 ; i< m.length(); i++) {
if(m.charAt(i)>='a' && m.charAt(i)<='z' ){
                    c2[m.charAt(i)-97]++;
}
}

for (int i=0 ;i<26;i++) {
int j = Math.min(c1[i],c2[i]);
for(int m1 =0; m1<j;m1++){
sbr.append((char)(97+i));
}
}
sbr.append("\n");

}
System.out.print(sbr);
}

}