http://arungupta1.blogspot.in/2012/07/tracy-and-taddy-competition-algo.html
I have Written this code by myself so please go through this ......
import java.util.*;
import java.lang.*;
import java.io.*;
public class AStringGame {
public static void main (String [] args)
{
HashMap hm = new HashMap();
String turn = new String("Taddy");
Scanner sc = new Scanner(System.in);
int test_case = sc.nextInt();
Set set = hm.entrySet();
//bool last = true;
Iterator ik = set.iterator();
int who = 0; // 0 teddy 1 1 tracy
int left = 0;
for(int i = 0 ; i<test_case ; ++i)
{
//String arr = new String("array"+i+"string");
//System.out.println("\n"+arr);
//int " arr"[] = new int[20];
String input = sc.next();
int len =input.length();
char[] iArray = input.toCharArray();
int inputs = sc.nextInt();
for(int j = 0 ; j< inputs ; ++j)
{
String arr = new String("array"+i+":"+j+"string");
//System.out.println("\n"+arr);
hm.put(arr,new String( sc.next()));
//System.out.println(hm.get(arr));
String in = (String) hm.get(arr);
int lenn = in.length();
//System.out.println(":::::::"+lenn);
who = 0 ;
int t = 0;
int ine = 0;
char[] aArray = in.toCharArray();
int start = 0 , end = 0;
for(int k = 0 ; k <len; ++k)
{
if(iArray[k] == aArray[0])
{
int counter = k;
start = k;
while(t < lenn)
{
if(iArray[counter] == aArray[t])
{
//System.out.println("startinput:"+counter+"\t:check string "+t );
who = 1;
end = counter;
if((lenn -1) ==(t) )
{
//System.out.println("Hey i am also here in if ");
//System.out.println("\nSome 1 Won");
t =9898;
left = inputs -1;
//System.out.println("Left *********************:"+left);
if(ine == 0)
{
turn = "Tracy";
ine = 1;
}else
{
turn = "Taddy";
ine = 0;
}
for(int gg = start ; gg <= end ;++gg)
{
iArray[gg] = '\0';
}
break;
//System.out.println("Hey i am also here in if ");
}
//System.out.printf("\nInside\n");
++counter;
++t;
}
else if(t< lenn)
{
//System.out.println("\nI am also here \n");
//System.out.println("\n Some one is going to looseclea");
t =0;
counter = 0;
who = 0;
//left = left +1;
break;
}
if(t == (len-1) )
{ break; }
}
}
if(t == (len-1) )
{ break; }
}
if(who == 0)
{
int oo = 0;
//System.out.println("Success Success");
}
}
/*while(ik.hasNext()) {
//Map.Entry me = (Map.Entry)ik.next();
System.out.print(hm.getKey() + ": ");
System.out.println(hm.getValue());
} */
/*if ((left%2) == 0)
{
System.out.println("Tracy");
}
else
System.out.println("Taddy");
*/
System.out.println("\n"+turn);
}
}
}
I have Written this code by myself so please go through this ......
import java.util.*;
import java.lang.*;
import java.io.*;
public class AStringGame {
public static void main (String [] args)
{
HashMap hm = new HashMap();
String turn = new String("Taddy");
Scanner sc = new Scanner(System.in);
int test_case = sc.nextInt();
Set set = hm.entrySet();
//bool last = true;
Iterator ik = set.iterator();
int who = 0; // 0 teddy 1 1 tracy
int left = 0;
for(int i = 0 ; i<test_case ; ++i)
{
//String arr = new String("array"+i+"string");
//System.out.println("\n"+arr);
//int " arr"[] = new int[20];
String input = sc.next();
int len =input.length();
char[] iArray = input.toCharArray();
int inputs = sc.nextInt();
for(int j = 0 ; j< inputs ; ++j)
{
String arr = new String("array"+i+":"+j+"string");
//System.out.println("\n"+arr);
hm.put(arr,new String( sc.next()));
//System.out.println(hm.get(arr));
String in = (String) hm.get(arr);
int lenn = in.length();
//System.out.println(":::::::"+lenn);
who = 0 ;
int t = 0;
int ine = 0;
char[] aArray = in.toCharArray();
int start = 0 , end = 0;
for(int k = 0 ; k <len; ++k)
{
if(iArray[k] == aArray[0])
{
int counter = k;
start = k;
while(t < lenn)
{
if(iArray[counter] == aArray[t])
{
//System.out.println("startinput:"+counter+"\t:check string "+t );
who = 1;
end = counter;
if((lenn -1) ==(t) )
{
//System.out.println("Hey i am also here in if ");
//System.out.println("\nSome 1 Won");
t =9898;
left = inputs -1;
//System.out.println("Left *********************:"+left);
if(ine == 0)
{
turn = "Tracy";
ine = 1;
}else
{
turn = "Taddy";
ine = 0;
}
for(int gg = start ; gg <= end ;++gg)
{
iArray[gg] = '\0';
}
break;
//System.out.println("Hey i am also here in if ");
}
//System.out.printf("\nInside\n");
++counter;
++t;
}
else if(t< lenn)
{
//System.out.println("\nI am also here \n");
//System.out.println("\n Some one is going to looseclea");
t =0;
counter = 0;
who = 0;
//left = left +1;
break;
}
if(t == (len-1) )
{ break; }
}
}
if(t == (len-1) )
{ break; }
}
if(who == 0)
{
int oo = 0;
//System.out.println("Success Success");
}
}
/*while(ik.hasNext()) {
//Map.Entry me = (Map.Entry)ik.next();
System.out.print(hm.getKey() + ": ");
System.out.println(hm.getValue());
} */
/*if ((left%2) == 0)
{
System.out.println("Tracy");
}
else
System.out.println("Taddy");
*/
System.out.println("\n"+turn);
}
}
}
No comments:
Post a Comment