Thursday, 23 January 2014

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 
Previous Post
Next Post

0 comments:

Advertisement