Saturday, 25 January 2014

UVa Problem ID 11308 (Bankrupt Banker)

UVa Problem ID 11308 (Bankrupt Banker)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.TreeSet;

public class Main
{
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb=new StringBuffer("");
        int testcases=Integer.parseInt(br.readLine());
        if(testcases<1 || testcases>100)
        	System.exit(0);
        for (int t = 0; t < testcases; t++)
		{
        	
        	sb.append(br.readLine().toUpperCase()+"\n");
        	String s[]=br.readLine().split(" ");
        	int m=Integer.parseInt(s[0]);
        	int n=Integer.parseInt(s[1]);
        	int b=Integer.parseInt(s[2]);
        	
        	if(m<1 || m>100 || n<1 || n>100 || b<1 || b>1000000)
        		break;
        	
        	HashMap ingredientcost=new HashMap<>();
        	TreeSet recipes=new TreeSet<>(new Comparator()
			{
				@Override
				public int compare(Recipe r1,Recipe r2)
				{
					if(r1.cost>r2.cost)
						return 1;
					else if(r1.cost==r2.cost)
						return r1.name.compareTo(r2.name);
					else
						return -1;
				}
			});
        	for (int i = 0; i 100)
					break;
				int cost=0;
				for (int j = 0; j < k; j++)
				{
					String s2[]=br.readLine().split(" ");
					cost+=ingredientcost.get(s2[0])*Integer.parseInt(s2[1]);
				}
				//System.out.println("cost ="+cost);
				r1.cost=cost;
				recipes.add(r1);
			}
        	boolean inbudget=false;
        	Iterator i=recipes.iterator();
        	while (i.hasNext())
			{
				Recipe recipe = (Recipe) i.next();
				if(recipe.cost<=b)
				{
					inbudget=true;
					sb.append(recipe.name+"\n");
				}
			}
        	if(!inbudget)
        	{
        		sb.append("Too expensive!\n");
        	}
        	sb.append("\n");
		}
        System.out.print(sb);
    }
}
class Recipe
{
	String name;
	int cost;
	
	public Recipe(String s)
	{
		name=s;
	}
}

UVa Problem ID 11495 (Bubbles and Buckets)

UVa Problem ID 11495 (Bubbles and Buckets)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	static long swapcount=0;
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb=new StringBuffer("");
        while(true)
        {
        	swapcount=0;
        	String s[]=br.readLine().split(" ");
	        int n=Integer.parseInt(s[0]);
	        if(n<2 || n>100000)
	        	break;
	        int a[]=new int[n];
	
	        for (int i = 0; i < n; i++) {
	        	a[i]=Integer.parseInt(s[i+1]);
				if(a[i]<1 || a[i]>n)
					System.exit(0);
				
			}

	        merge_sort(a,0,a.length-1);

	        if(swapcount%2==0)
	        	sb.append("Carlos");
	        else
	        	sb.append("Marcelo");
	        sb.append("\n");
        }
        System.out.print(sb);
    }
	public static void merge_sort(int[] a,int start,int end) {
			if(startmiddle)
			{
				combinedarray[k]=a[j++];
			}
			else if(j>end)
			{
				combinedarray[k]=a[i++];
			}
			else
			{
				if(a[i]>a[j])
				{
					combinedarray[k]=a[j++];
					swapcount+=middle-i+1;
				}
				else
					combinedarray[k]=a[i++];
			}
			
		}
		int p=0;
		for (int j2 = start; j2 <=end; j2++)
		{
			a[j2]=combinedarray[p++];
		}
	}	
	

}

UVa Problem ID 10810 (Ultra Quicksort)

UVa Problem ID 10810 (Ultra Quicksort)
//Note :- use long , int is not enough

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

public class Main {
	static long swapcount=0;
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb=new StringBuffer("");
        while(true)
        {
        	swapcount=0;
	        int n=Integer.parseInt(br.readLine());
	        if(n==0 || n>500000)
	        	break;
	        long a[]=new long[n];
	
	        for (int i = 0; i < n; i++) {
	        	a[i]=Long.parseLong(br.readLine());
				if(a[i]<0 || a[i]>999999999)
					break;
				
			}
//	        for (int i = 0; i < a.length; i++) {
//				System.out.print(a[i]+" ");
//			}
//	        System.out.println("");
	        merge_sort(a,0,a.length-1);
//	        for (int i = 0; i < a.length; i++) {
//				System.out.print(a[i]+" ");
//			}
//	        System.out.println("");
	        sb.append(swapcount+"\n");
        }
        System.out.print(sb);
    }
	public static void merge_sort(long[] a,int start,int end) {
			if(startmiddle)
			{
				combinedarray[k]=a[j++];
			}
			else if(j>end)
			{
				combinedarray[k]=a[i++];
			}
			else
			{
				if(a[i]>a[j])
				{
					combinedarray[k]=a[j++];
					swapcount+=middle-i+1;
				}
				else
					combinedarray[k]=a[i++];
			}
			
		}
		int p=0;
		for (int j2 = start; j2 <=end; j2++)
		{
			a[j2]=combinedarray[p++];
		}
	}	
	

}

UVa Problem ID 673 (Parentheses Balance)

UVa Problem ID 673 (Parentheses Balance)

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

public class Main
{
	public static void main(String[] args) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input;
		StringBuffer sb = new StringBuffer("");
		int testcases = Integer.parseInt(br.readLine());

		for (int i = 0; i < testcases; i++)
		{
			boolean iscorrect = true;
			input = br.readLine();
			Stack st = new Stack();
			for (int j = 0; j < input.length(); j++)
			{
				if (iscorrect)
				{
					switch (input.charAt(j))
					{
						case '(':
						{
							st.push('(');
							break;
						}
						case '[':
						{
							st.push('[');
							break;
						}
						case ']':
						{
							if(st.isEmpty())
							{
								iscorrect=false;
								break;
							}
							char c = st.pop();
							if (c != '[')
							{
								iscorrect = false;
							}
							break;
						}
						case ')':
						{
							if(st.isEmpty())
							{
								iscorrect=false;
								break;
							}
							char c = st.pop();
							if (c != '(')
							{
								iscorrect = false;
							}
							break;
						}
					}
				}
			}
			if(iscorrect && st.isEmpty())
				sb.append("Yes");
			else
				sb.append("No");
			sb.append("\n");
		}
		System.out.print(sb);
	}

}

UVa Problem ID 458 (The Decoder)

UVa Problem ID 458 (The Decoder)
//Note:-be careful about encoding

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

public class Main {
	public static void main(String[] args) throws IOException 
    {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in,"ISO-8859-1"));        
		OutputStreamWriter cout = new OutputStreamWriter(System.out, "ISO-8859-1");

        StringBuffer sb=new StringBuffer("");
        String input;
        while ((input=br.readLine())!=null) {
        	for (int i = 0; i 

UVa Problem ID 10071 (Back To High School Physics)

UVa Problem ID 10071 (Back To High School Physics)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb=new StringBuffer("");
        String input;
        while ((input=br.readLine())!=null) {
			String s[]=input.split(" ");
			int v=Integer.parseInt(s[0]);
			int t=Integer.parseInt(s[1]);
			if(v<-100 || v>100 || t<0 || t>200)
				break;
			sb.append((2*v*t));
			sb.append("\n");
        }
        System.out.print(sb);
    }
}

UVa Problem ID 11462 (Age Sort)

UVa Problem ID 11462 (Age Sort)
//Note :-another approach use counting sort

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

public class Main {
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb=new StringBuffer("");
        while(true)
    	{
	    	int n=Integer.parseInt(br.readLine());
	    	if(n<=0 || n>2000000)
	        	break;
	        String s[]=br.readLine().split(" ");
	        int ages[]=new int[n];
	        for (int i = 0; i 

Thursday, 23 January 2014

UVa Problem ID 612 (DNA Sorting)

UVa Problem ID 612 (DNA Sorting)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input;
        StringBuffer sb=new StringBuffer("");
        int M=Integer.parseInt(br.readLine());
        boolean blank = false;
       
        for (int i = 0; i 50 || m<=0 || m>100)
				break;
			
			String in[]=new String[m];
			int value[]=new int[m];
			
			
			for (int j = 0; j input.charAt(j2))
						{
							total+=1;
						}
					}
				}
				
				in[j]=input;
				value[j]=total;
			}
			
			for(int j=1;j0 && value[j2-1]>value[j2])
	            {
	                int temp=value[j2-1];
	                value[j2-1]=value[j2];
	                value[j2]=temp;
	                String s1=in[j2-1];
					in[j2-1]=in[j2];
					in[j2]=s1;
	                j2--;
	            }
	            
	        }
			
			if ( blank ) sb.append("\n");
	        blank = true;
			for (int j = 0; j < m; j++) {
//				if(in[j]==null)
//					in[j]="";
				sb.append(in[j]+"\n");
				
			}
			
		}
        System.out.print(sb);
    }
	
}

UVa Problem ID 299 (Train Swapping)

UVa Problem ID 299 (Train Swapping)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb=new StringBuffer("");
        int testcases=Integer.parseInt(br.readLine());
        for (int i = 0; i 50)
        		System.exit(0);
        	int a[]=new int[L];
        	String s[]=br.readLine().split(" ");
        	for(int j=0;ja[j2])
					{
						int temp=a[j2];
						a[j2]=a[j];
						a[j]=temp;
						swapcount++;
					}
				}
			}
        	sb.append("Optimal train swapping takes "+swapcount+" swaps.\n");
        }
        System.out.print(sb);
    }
}

UVa Problem ID 10055 (Hashmat The Brave Warrior)

UVa Problem ID 10055 (Hashmat The Brave Warrior)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb=new StringBuffer("");
        String input;
        while ((input=br.readLine())!=null) {
			String s[]=input.split(" ");
			long a=Long.parseLong(s[0]);
			long b=Long.parseLong(s[1]);
			if(a>b)
				sb.append((a-b));
			else
				sb.append((b-a));
			sb.append("\n");
		}
        System.out.print(sb);
    }
}

UVa Problem ID 10258 (Contestant scoreboard)

UVa Problem ID 10258 (Contestant scoreboard)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;

public class Main {
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb=new StringBuffer("");
        String input;
        int testcases=Integer.parseInt(br.readLine());
        br.readLine();
        for (int i = 0; i 0)
        		sb.append("\n");
			
			int no_of_contestants=0;
			Contestant contestants[]=new Contestant[100];
			 while ((input = br.readLine()) != null) {
	                if (input.trim().equals("")) {
	                    break;
	                }
				String s[]=input.split(" ");
				//System.out.println("**********"+input+"*********");
				if(Integer.parseInt(s[0]) < 0 || Integer.parseInt(s[0])>100 ||Integer.parseInt(s[1])<1 ||Integer.parseInt(s[1])>9)
						break;
				boolean found=false;
				Contestant c=null;
				for (int j = 0; j 
{
	int number;
	int problemsolved;
	int totaltime;
	HashMap unsolved=new HashMap();
	HashMap solved=new HashMap();
	public Contestant(int no)
	{
		number=no;
	}
		
	@Override
	public int compareTo(Contestant B) {
		if(this.problemsolved>B.problemsolved)
			return -1;
		else if(this.problemsolvedB.totaltime)
				return +1;
			else
			{
				if(this.number

UVa Problem ID 10194 (Football)

UVa Problem ID 10194 (Football)
/*Note:-
!!! The default system encoding is different from the judge data files. !!!

For the detail, please reference this thread:
http://acm.uva.es/board/viewtopic.php?f=10&t=32047&start=30#p140856
 
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Comparator;

public class Main {
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in,"ISO-8859-1"));
        OutputStreamWriter cout = new OutputStreamWriter(System.out, "ISO-8859-1");
        StringBuffer sb=new StringBuffer("");
        int N=Integer.parseInt(br.readLine());
        if(N<=0 || N>1000)
        	System.exit(0);
        for (int k1 = 0; k1 0)
        		sb.append("\n");
        	String tournamentname=br.readLine();
        	if(tournamentname.length()<0 || tournamentname.length()>100)
        		break;
        	sb.append(tournamentname+"\n");
        	int T=Integer.parseInt(br.readLine());
        	if(T<=1 || T>30)
        		break;
        	
        	Team teams[]=new Team[T];
        	for (int i = 0; i 30)
        			System.exit(0);
        		for (int j = 0; j < s.length(); j++) {
					if(s.charAt(j)<32 || s.charAt(j)=='#' || s.charAt(j)=='@')
						System.exit(0);
				}
        		Team t=new Team(s);
        		teams[i]=t;
			}
        	int G=Integer.parseInt(br.readLine());
        	if(G<0 || G>1000)
        		break;
        	for (int i = 0; i =20 || goal2<0 ||goal2 >=20)
					break;
        		for (int j = 0; j < teams.length; j++) {
					if(teams[j].name.equals(s[0]))
					{
						if(goal1>goal2)
							teams[j].win++;
						else if(goal1==goal2)
							teams[j].tie++;
						else
							teams[j].losses++;
						teams[j].goalscored+=goal1;
						teams[j].goalagainst+=goal2;
					}
					if(teams[j].name.equals(s[2]))
					{
						if(goal2>goal1)
							teams[j].win++;
						else if(goal1==goal2)
							teams[j].tie++;
						else
							teams[j].losses++;
						teams[j].goalscored+=goal2;
						teams[j].goalagainst+=goal1;
					}
				}
        		
			}
        	
        	Arrays.sort(teams,new Team());
        	for (int j = 0; j < teams.length; j++) {
				sb.append((j+1)+") "+teams[j].name+" "+(teams[j].win*3+teams[j].tie*1)+"p, "+(teams[j].win+teams[j].tie+teams[j].losses)+"g ("+teams[j].win+"-"+teams[j].tie+"-"+teams[j].losses+"), "+(teams[j].goalscored-teams[j].goalagainst)+"gd ("+teams[j].goalscored+"-"+teams[j].goalagainst+")");
				sb.append("\n");
			}
        }
        cout.write(sb.toString());
        cout.flush();
    }
}
class Team implements Comparator
{
	String name;
	int win;
	int tie;
	int losses;
	int goalscored;
	int goalagainst;
	
	public Team(String s)
	{
		name=s;
	}
	public Team()
	{

	}
	
	@Override
	public int compare(Team A, Team B) {
		// TODO Auto-generated method stub
		if((A.win*3+A.tie*1)>(B.win*3+B.tie*1))
			return -1;
		else if((A.win*3+A.tie*1)<(B.win*3+B.tie*1))
			return +1;
		else
		{
			if(A.win>B.win)
				return -1;
			else if(A.win(B.goalscored-B.goalagainst))
					return -1;
				else if((A.goalscored-A.goalagainst)<(B.goalscored-B.goalagainst))
					return +1;
				else
				{
					if(A.goalscored>B.goalscored)
						return -1;
					else if(A.goalscored(B.win+B.tie+B.losses))
							return +1;
						else
							return A.name.compareToIgnoreCase(B.name);

					}
				}
			}
		}
	}
}

UVa Problem ID 11340 (Newspaper)

UVa Problem ID 11340 (Newspaper)
//Note:-use long to get the total cent int is not enough

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

public class Main {
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
       
        int N=Integer.parseInt(br.readLine());
        if(N<=0 || N>5)
        	System.exit(0);
        for (int k1 = 0; k1 100)
        	System.exit(0);
        HashMap m=new HashMap();
        long cost = 0;
        for (int i = 0; i 150000)
        	System.exit(0);
        for (int i = 0; i 10000)
        		break;
        	for (int j = 0; j 

UVa Problem ID 594 (One Little, Two Little, Three Little Endians)

UVa Problem ID 594 (One Little, Two Little, Three Little Endians)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input;
        StringBuffer sb=new StringBuffer("");
       
        while((input=br.readLine())!=null)
        {
        	int n=Integer.parseInt(input);
        	sb.append(n+" converts to "+Integer.reverseBytes(n)+"\n");
        }
        System.out.print(sb);
    }
}

UVa Problem ID 11727 (Cost Cutting)

UVa Problem ID 11727 (Cost Cutting)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb=new StringBuffer("");
       
        int t=Integer.parseInt(br.readLine());
        if(t>20)
        	System.exit(0);
        for (int i = 0; i 10000 || b<1000 || b>10000 || c<1000 || c>10000 || a==b || a==c || b==c)
        		break;
        	int middle=a;
        	if((a

UVa Problem ID 482 (Permutation Arrays)

UVa Problem ID 482 (Permutation Arrays)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
 public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb=new StringBuffer("");
       
        int t=Integer.parseInt(br.readLine());
        if(t<0)
         System.exit(0);
        for (int i = 0; i s1.length)
          min=s1.length;
         for (int j = 0; j 0)
          sb.append("\n");
         for (int j = 0; j < a.length; j++) {
          if(a[j]==null)
           a[j]="";
    sb.append(a[j]+"\n");
   }
         
        }
        System.out.print(sb);
    }

}

UVa Problem ID 11223 (O: dah dah dah!)

UVa Problem ID 11223 (O: dah dah dah!)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input;
        StringBuffer sb=new StringBuffer("");
       
        int t=Integer.parseInt(br.readLine());
        if(t<1 || t>10)
        	System.exit(0);
        for (int i = 0; i 2000)
        		break;
        	int start=0;
        	boolean flag=false;
        	
        	sb.append("Message #"+(i+1)+"\n");
        	while(true)
        	{
        		String s;
        		if(input.indexOf(" ",start)!=-1)
        		{
        			s=input.substring(start,input.indexOf(" ",start));
        			start=input.indexOf(" ",start)+1;
           		}
        		else
        		{
        			s=input.substring(start);
            		flag=true;
        		}
        		//System.out.println("____"+s+"______");
        		switch(s)
        		{
        			case ".-":
        			{
        				sb.append("A");
        				break;
        			}
        			case "-...":
        			{
        				sb.append("B");
        				break;
        			}
        			case "-.-.":
        			{
        				sb.append("C");
        				break;
        			}
        			case "-..":
        			{
        				sb.append("D");
        				break;
        			}
        			case ".":
        			{
        				sb.append("E");
        				break;
        			}
        			case "..-.":
        			{
        				sb.append("F");
        				break;
        			}
        			case "--.":
        			{
        				sb.append("G");
        				break;
        			}
        			case "....":
        			{
        				sb.append("H");
        				break;
        			}
        			case "..":
        			{
        				sb.append("I");
        				break;
        			}
        			case ".---":
        			{
        				sb.append("J");
        				break;
        			}
        			case "-.-":
        			{
        				sb.append("K");
        				break;
        			}
        			case ".-..":
        			{
        				sb.append("L");
        				break;
        			}
        			case "--":
        			{
        				sb.append("M");
        				break;
        			}
        			case "-.":
        			{
        				sb.append("N");
        				break;
        			}
        			case "---":
        			{
        				sb.append("O");
        				break;
        			}
        			case ".--.":
        			{
        				sb.append("P");
        				break;
        			}
        			case "--.-":
        			{
        				sb.append("Q");
        				break;
        			}
        			case ".-.":
        			{
        				sb.append("R");
        				break;
        			}
        			case "...":
        			{
        				sb.append("S");
        				break;
        			}
        			case "-":
        			{
        				sb.append("T");
        				break;
        			}
        			case "..-":
        			{
        				sb.append("U");
        				break;
        			}
        			case "...-":
        			{
        				sb.append("V");
        				break;
        			}
        			case ".--":
        			{
        				sb.append("W");
        				break;
        			}
        			case "-..-":
        			{
        				sb.append("X");
        				break;
        			}
        			case "-.--":
        			{
        				sb.append("Y");
        				break;
        			}
        			case "--..":
        			{
        				sb.append("Z");
        				break;
        			}
        			case "-----":
        			{
        				sb.append("0");
        				break;
        			}
        			case ".----":
        			{
        				sb.append("1");
        				break;
        			}
        			case "..---":
        			{
        				sb.append("2");
        				break;
        			}
        			case "...--":
        			{
        				sb.append("3");
        				break;
        			}
        			case "....-":
        			{
        				sb.append("4");
        				break;
        			}
        			case ".....":
        			{
        				sb.append("5");
        				break;
        			}
        			case "-....":
        			{
        				sb.append("6");
        				break;
        			}
        			case "--...":
        			{
        				sb.append("7");
        				break;
        			}
        			case "---..":
        			{
        				sb.append("8");
        				break;
        			}
        			case "----.":
        			{
        				sb.append("9");
        				break;
        			}
        			case ".-.-.-":
        			{
        				sb.append(".");
        				break;
        			}
        			case "--..--":
        			{
        				sb.append(",");
        				break;
        			}
        			case "..--..":
        			{
        				sb.append("?");
        				break;
        			}
        			case ".----.":
        			{
        				sb.append("'");
        				break;
        			}
        			case "-.-.--":
        			{
        				sb.append("!");
        				break;
        			}
        			case "-..-.":
        			{
        				sb.append("/");
        				break;
        			}
        			case "-.--.":
        			{
        				sb.append("(");
        				break;
        			}
        			case "-.--.-":
        			{
        				sb.append(")");
        				break;
        			}
        			case ".-...":
        			{
        				sb.append("&");
        				break;
        			}
        			case "---...":
        			{
        				sb.append(":");
        				break;
        			}
        			case "-.-.-.":
        			{
        				sb.append(";");
        				break;
        			}
        			case "-...-":
        			{
        				sb.append("=");
        				break;
        			}
        			case ".-.-.":
        			{
        				sb.append("+");
        				break;
        			}
        			case "-....-":
        			{
        				sb.append("-");
        				break;
        			}
        			case "..--.-":
        			{
        				sb.append("_");
        				break;
        			}
        			case ".-..-.":
        			{
        				sb.append("\"");
        				break;
        			}
        			case ".--.-.":
        			{
        				sb.append("@");
        				break;
        			}
        			default:
        			{
        				sb.append(" ");
        				break;
        			}
        		}
        		if(flag)
        			break;
        	}
        	if(i+1==t)
        		sb.append("\n");
        	else
        	{
        		sb.append("\n");sb.append("\n");
        	}
        	
        }
        System.out.print(sb);
    }
}

UVa Problem ID 11498 (Division of Nlogonia)

UVa Problem ID 11498 (Division of Nlogonia)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb=new StringBuffer("");
        while(true)
        {
	        int K=Integer.parseInt(br.readLine());
	        if(K<=0 || K>1000)
	        	break;
	        String s[]=br.readLine().split(" ");
	        int N=Integer.parseInt(s[0]);
	        int M=Integer.parseInt(s[1]);
	        if(N<-10000 || N>10000 || M<-10000 || M>10000)
	        	break;
	        for (int i = 0; i 10000 || Y<-10000 || Y>10000)
	            	break;
	            //System.out.println("K="+K+" N="+N+" M="+M+" X="+X+" Y="+Y);
	            if(X==N || Y==M)
	            {
	            	sb.append("divisa");
	            }
	            else if(XM)
	            {
	            	sb.append("NO");
	            }
	            else if(XN && Y>M)
	            {
	            	sb.append("NE");
	            }
	            else if(X>N && Y

UVa Problem ID 11547 (Automatic Answer)

UVa Problem ID 11547 (Automatic Answer)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input;
        StringBuffer sb=new StringBuffer("");
       
        int t=Integer.parseInt(br.readLine());
        if(t<1 || t>100)
        	System.exit(0);
        for (int i = 0; i 1000)
            	break;
        	String s=""+(315*n+36962);
        	if(s.length()>=2)
        		sb.append(s.charAt(s.length()-2));
        	else
        		sb.append(0);
        	sb.append("\n");
        }
        System.out.print(sb);
    }
}

UVa Problem ID 11044 (Searching For Nessy)

UVa Problem ID 11044 (Searching For Nessy)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb=new StringBuffer("");
       
        int t=Integer.parseInt(br.readLine());
        for (int i = 0; i 10000 || m<6 ||m>10000)
				break;
			int ans=(int)(Math.ceil((n-2)/3.0)*Math.ceil((m-2)/3.0));
			sb.append(ans);
			sb.append("\n");
		}
        System.out.print(sb);
    }
}

UVa Problem ID 10921 (Find the Telephone)

UVa Problem ID 10921 (Find the Telephone)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input;
        StringBuffer sb=new StringBuffer("");
       
        while((input=br.readLine())!=null)
        {
		if(input.length()<1 ||input.length()>30)
        		break;
        	for (int i = 0; i < input.length(); i++) 
        	{
				switch (input.charAt(i)) 
				{
					case '1':
					case '-':
					case '0':
					{
						sb.append(input.charAt(i));
						break;
					}
					case 'A':
					case 'B':
					case 'C':
					{
						sb.append(2);
						break;
					}
					case 'D':
					case 'E':
					case 'F':
					{
						sb.append(3);
						break;
					}
					case 'G':
					case 'H':
					case 'I':
					{
						sb.append(4);
						break;
					}
					case 'J':
					case 'K':
					case 'L':
					{
						sb.append(5);
						break;
					}
					case 'M':
					case 'N':
					case 'O':
					{
						sb.append(6);
						break;
					}
					case 'P':
					case 'Q':
					case 'R':
					case 'S':
					{
						sb.append(7);
						break;
					}
					case 'T':
					case 'U':
					case 'V':
					{
						sb.append(8);
						break;
					}
					case 'W':
					case 'X':
					case 'Y':
					case 'Z':
					{
						sb.append(9);
						break;
					}
				}
			}
        	sb.append("\n");
        }
        System.out.print(sb);
    }
}

UVa Problem ID 10812 (Beat the Spread)

UVa Problem ID 10812 (Beat the Spread)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb=new StringBuffer("");
       
        int n=Integer.parseInt(br.readLine());
        for (int i = 0; i s || (s+d)%2!=0)
			{
				sb.append("impossible");
			}
			else if(d==s)
			{
				sb.append(s+" "+0);
			}
			else
			{
				int a=(s+d)/2;
				sb.append(a+" "+(s-a));
			}
			sb.append("\n");
		}
        System.out.print(sb);
    }
}

UVa Problem ID 10683 (The decadary watch)

UVa Problem ID 10683 (The decadary watch)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	 public static void main(String[] args) throws IOException 
	    {
	        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	        String input;
	        StringBuffer sb=new StringBuffer("");
	       
	        while((input=br.readLine())!=null)
	        {
	        	int HH=Integer.parseInt(input.substring(0,2));
	        	int MM=Integer.parseInt(input.substring(2,4));
	        	int SS=Integer.parseInt(input.substring(4,6));
	        	int CC=Integer.parseInt(input.substring(6));
	        	if(HH<0 || HH>59 || MM<0 || MM>59 || SS<0 || SS>59 || CC <0 || CC>99)
	        		break;
	        	//System.out.println("HH ="+HH+" MM="+MM+" SS="+SS+" CC="+CC);
	        	int decimaltimestring=(HH*360000+MM*6000+SS*100+CC)*125/108;
	        	StringBuffer s=new StringBuffer(decimaltimestring+"");
	        	if(s.length()<7)
	        	{
	        		while (s.length()!=7) {
						s.insert(0,'0');
					}
	        	}
	        	sb.append(s);
	        	sb.append("\n");
	        }
	        System.out.print(sb);
	    }
}

UVa Problem ID 10189 (Mine Sweeper)

UVa Problem ID 10189 (Mine Sweeper)
import java.io.IOException;
import java.util.StringTokenizer;

class Main implements Runnable {

    static String ReadLn(int maxLength) {  // utility function to read from stdin,
        // Provided by Programming-challenges, edit for style only
        byte line[] = new byte[maxLength];
        int length = 0;
        int input = -1;
        try {
            while (length < maxLength) {//Read untill maxlength
                input = System.in.read();
                if ((input < 0) || (input == '\n')) {
                    break; //or untill end of line ninput
                }
                line[length++] += input;
            }

            if ((input < 0) && (length == 0)) {
                return null;  // eof
            }
            return new String(line, 0, length);
        } catch (IOException e) {
            return null;
        }
    }

    public static void main(String args[]) // entry point from OS
    {
        Main myWork = new Main();  // Construct the bootloader
        myWork.run();            // execute
    }

    public void run() {
        new myStuff().run();
    }
}

class myStuff implements Runnable {
    public void run() {
        String input;
        java.util.StringTokenizer idata;
        int inputno = 0;

        while ((input = Main.ReadLn(255)) != null) {
            inputno++;
            idata = new StringTokenizer(input);
            int n = Integer.parseInt(idata.nextToken());
            int m = Integer.parseInt(idata.nextToken());
            if (n <= 0 || n > 100 || m <= 0 || m > 100) {
                break;
            }
            char inputpattern[][] = new char[n][m];
            for (int i = 0; i < n; i++) {
                String s = Main.ReadLn(255);
                for (int j = 0; j < m; j++) {
                    inputpattern[i][j] = s.charAt(j);
                }
            }
            int output[][] = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (inputpattern[i][j] == '*') {
                        if (i < n - 1) {
                            output[i + 1][j] += 1;
                            if (j > 0) {
                                output[i + 1][j - 1] += 1;
                            }
                            if (j < m - 1) {
                                output[i + 1][j + 1] += 1;
                            }
                        }
                        if (i > 0) {
                            output[i - 1][j] += 1;
                            if (j > 0) {
                                output[i - 1][j - 1] += 1;
                            }
                            if (j < m - 1) {
                                output[i - 1][j + 1] += 1;
                            }
                        }
                        if (j > 0) {
                            output[i][j - 1] += 1;
                        }
                        if (j < m - 1) {
                            output[i][j + 1] += 1;
                        }
                        output[i][j] = 10;
                    }
                }
            }
            if(inputno!=1)
            {
                System.out.println("");
            }
            System.out.println("Field #" + inputno + ":");
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (output[i][j] > 8) {
                        System.out.print("*");
                    } else {
                        System.out.print(output[i][j]);
                    }
                }
               System.out.println("");
            }
        }
    }
}

Uva Problem ID 10420(List of Conquests)

Uva Problem ID 10420(List of Conquests)
//Note:-there may be a country without womens name
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	 public static void main(String[] args) throws IOException 
	    {
	        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	        String input;
	        StringBuffer sb=new StringBuffer("");
	        int ncountry=0;
	        int n=Integer.parseInt(input=br.readLine());
	        //System.out.println("n="+n);
	        if(n>2000)
	        		System.exit(0);
	        String s[]=new String[n];
	        int count[]=new int[n];
	        for (int i = 0; i 75)
					System.exit(0);
				String s1[]=input.split(" ");
				String countryname=s1[0];
				
				for (int j = 0; j < ncountry; j++) {
					if(s[j].equals(countryname))
					{
						found=true;
						count[j]++;
					}
				}
				if(!found)
				{//System.out.println(countryname);
					s[ncountry]=countryname;
					count[ncountry]++;
					ncountry++;
				
				}
//				 for (int k = 0; k 0)
					{
						String temp=s[j];
						s[j]=s[i];
						s[i]=temp;
						int temp1=count[j];
						count[j]=count[i];
						count[i]=temp1;
					}
				}
			}
	        
	        for (int i = 0; i 

Advertisement