import java.io.*;
class card
{
static char[]Suits=new char[21];
static char[]Number=new char[21];
static char[][]StacksS=new char[3][7];
static char[][]StacksN=new char[3][7];
public static void ReAdjust(int a, int b)
{
for(int i=0; i<=6; i++)
{
char A=StacksS[a][i];
StacksS[a][i]=StacksS[b][i];
StacksS[b][i]=A;
A=StacksN[a][i];
StacksN[a][i]=StacksN[b][i];
StacksN[b][i]=A;
}
}
public static void D2Stacks()
{
int k=0;
for(int i=0; i<=6; i++)
{
for(int j=0; j<3; j++)
{
StacksS[j][i]=Suits[k];
StacksN[j][i]=Number[k++];
}
}
}
public static void D2Pile()
{
int k=0;
for(int i=0; i<3; i++)
{
for(int j=0; j<7; j++)
{
Suits[k]=StacksS[i][j];
Number[k++]=StacksN[i][j];
}
}
}
public static void Display(int a)
{
for(int i=0; i<=6; i++)
{
for(int j=0; j<3; j++)
{
for(int v=0; v<=888888; v++)
System.out.print("");
System.out.print(""+StacksS[j][i]+""+StacksN[j][i]+" ");
}
}
System.out.println();
System.out.println("(Please note: C=Club, H=Heart, D=Diamond, S=Spade, T=10)");
}
public static void Display()
{
System.out.println("Stack-1 Stack-2 Stack-3");
for(int i=0; i<=6; i++)
{
for(int a=0; a<=888888; a++)
System.out.print("");
for(int j=0; j<3; j++)
{
System.out.print(""+StacksS[j][i]+""+StacksN[j][i]+" ");
}
System.out.println("");
}
}
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
char[][]A=new char[4][13];
char[]B={'H', 'S', 'D', 'C'};
char[]C={'A',50,51,52,53,54,55,56,57,'T','J','Q','K'};
for(int i=0; i<=3; i++)
for(int j=0; j<=12; j++)
A[i][j]=C[j];
int q, b, c=0;
for(c=0; c<=20; c++)
{
do{
q=(int)(Math.random()*4);
b=(int)(Math.random()*13);
}while(A[q][b]==' ');
Suits[c]=B[q];
Number[c]=A[q][b];
A[q][b]=' ';
}
D2Stacks();
System.out.println("Select a card from the following cards in your mind: ");
for(int a=0; a<=888888; a++)
System.out.print("");
Display(1);
System.out.println("\n\nNow press enter: ");
String S=br.readLine();
D2Pile();
D2Stacks();
System.out.println("\n\nSelect the stack in which your card lies this time around: ");
Display();
System.out.println("\n\nNow type the stack number and press enter: ");
int a=Integer.parseInt(br.readLine());
if(a!=2)
ReAdjust(1, a-1);
for(int p=0; p<=888888; p++)
System.out.print("");
D2Pile();
D2Stacks();
System.out.println("\n\nSelect the stack in which your card lies for the last time now: ");
Display();
System.out.println("\n\nNow type the stack number and press enter: ");
a=Integer.parseInt(br.readLine());
if(a!=2)
ReAdjust(1, a-1);
for(int p=0; p<=888888; p++)
System.out.print("");
D2Pile();
D2Stacks();
System.out.println("\n\nSelect the stack in which your card lies: ");
Display();
System.out.println("\n\nNow type the stack number and press enter: ");
a=Integer.parseInt(br.readLine());
if(a!=2)
ReAdjust(1, a-1);
for(int p=0; p<=888888; p++)
System.out.print("");
System.out.print("You selected .");
for(int i=1; i<=399999999; i++)
if(i%122222222==0)
System.out.print(" .");
System.out.print(" "+StacksS[1][3]+""+StacksN[1][3]);
}
}
Very nice code.... I was searching about it.
ReplyDeleteThank you.
Excellent work Shivam!!
ReplyDelete