SPOJ problem---IITKWPCA ..is there any case left?

import java.io.*;
import java.util.Arrays;

class IITKP{
public static void main(String ar[])throws Exception{
DataInputStream s=new DataInputStream(System.in);

	int t=0,len=0,x=0,count=0,i=0;
	t=Integer.parseInt(s.readLine());
	String arr[]=new String[10000];
	String st="",str="";
	
	while(t>0){
	
		x=0;
		
		count=0;
		str=s.readLine();
	
			
		str=str+" ";
		len=str.length();
		if (str.trim().length()==0){
			System.out.println(0);
			t--;
			continue;
		}
			
			
		for(i=0;i<len;i++){
			if(str.charAt(i)!=' ')
				st=st+str.charAt(i);
			
			else{
				arr[x++]=st;
				while(i<len&&str.charAt(i)==' ')
					i++;
					
				i--;
				st="";
			}
		}
		Arrays.sort(arr,0,x);
		
	/*	for(i=0;i<x;i++)
			System.out.println(arr[i]);*/
		
		for(i=0;i<x;i++){
					
				count+=1;
			
			//System.out.println(arr[i]);
			while(i<(x-1)&&(arr[i].compareTo(arr[i+1]))==0){
				i++;
				//System.out.println(arr[i]);
			}
			
		}
		
		System.out.println(count);
		t--;
	}
	
}

}

your code looks horrible…

there’s no need to mess up this much for this question… its an easy task

you can simply make use of ‘Set’ :wink:

I did it in just 4 lines in python

1 Like