101 - The Blocks Problem
Moderator: Board moderators
Problem 101 - Wrong Answer
i don't know why, I get the Wrong Answer........
Please hELp.....
[pascal]
program p101;
var
i,j,n:integer;
s:string;
p:array [0..25,0..25] of byte;
fpos,fh,tpos,th:integer;
ss,sss:string;
mf,mt:integer;
temp:integer;
procedure search(block:integer; var pos1,height:integer);
var i,j:integer;
begin
for i:=0 to n-1 do
for j:=1 to p[i,0] do
if (p[i,j] = block) then
begin
pos1:=i;
height:=j;
exit;
end;
height:=0;
pos1:=n;
end;
procedure analysis(s:string);
var i,v:integer;
s1:string;
begin
delete(s,1,pos(' ',s));
s1:=copy(s,1,pos(' ',s)-1);
val(s1,mf,i);
delete(s,1,pos(' ',s));
sss:=copy(s,1,pos(' ',s)-1);
delete(s,1,pos(' ',s));
val(s,mt,i);
end;
procedure output;
var i,j:integer;
begin
for i:=0 to n-1 do
begin
write(' ',i,':');
for j:=1 to p[i,0] do
write(' ',p[i,j]);
writeln;
end;
end;
begin
readln(n);
for i:=0 to 25 do
for j:=1 to 25 do
p[i,j]:=0;
for i:=0 to n-1 do
begin
p[i,1]:=i;
p[i,0]:=1;
end;
while not (eof(input)) do
begin
readln(s);
if (pos('quit',s) <> 0) then
break;
ss:=copy(s,1,4);
analysis(s);
if (mf >= n) or (mt >= n) then
continue;
search(mf,fpos,fh);
search(mt,tpos,th);
if (fpos >= n) or (tpos >= n) or (fh = 0) or (th = 0) then continue;
if (fpos = tpos) or (mf = mt) then continue;
if (ss = 'move') and (fh = p[fpos,0]) then
if (sss = 'onto') and (th = p[tpos,0]) then
begin
p[tpos,0]:=p[tpos,0] + 1;
p[tpos, p[tpos,0]]:=p[fpos, p[fpos,0]];
p[fpos,0]:=p[fpos,0] - 1;
end
else
if (sss = 'over') then
begin
p[tpos,0]:=p[tpos,0] + 1;
p[tpos, p[tpos,0]]:=p[fpos, p[fpos,0]];
p[fpos,0]:=p[fpos,0] - 1;
end;
if (ss = 'pile') then
if (sss = 'onto') and (th = p[tpos,0]) then
begin
temp:=1+( p[fpos,0] - fh);
for i:=1 to temp do
begin
p[tpos,0]:=p[tpos,0] + 1;
p[tpos, p[tpos,0]]:=p[fpos, fh+i-1];
p[fpos,0]:=p[fpos,0] - 1;
end;
end
else
if (sss = 'over') then
begin
temp:=1+( p[fpos,0] - fh);
for i:=1 to temp do
begin
p[tpos,0]:=p[tpos,0] + 1;
p[tpos, p[tpos,0]]:=p[fpos, fh+i-1];
p[fpos,0]:=p[fpos,0] - 1;
end;
end;
end;
output;
end.
[/pascal]
Please hELp.....
[pascal]
program p101;
var
i,j,n:integer;
s:string;
p:array [0..25,0..25] of byte;
fpos,fh,tpos,th:integer;
ss,sss:string;
mf,mt:integer;
temp:integer;
procedure search(block:integer; var pos1,height:integer);
var i,j:integer;
begin
for i:=0 to n-1 do
for j:=1 to p[i,0] do
if (p[i,j] = block) then
begin
pos1:=i;
height:=j;
exit;
end;
height:=0;
pos1:=n;
end;
procedure analysis(s:string);
var i,v:integer;
s1:string;
begin
delete(s,1,pos(' ',s));
s1:=copy(s,1,pos(' ',s)-1);
val(s1,mf,i);
delete(s,1,pos(' ',s));
sss:=copy(s,1,pos(' ',s)-1);
delete(s,1,pos(' ',s));
val(s,mt,i);
end;
procedure output;
var i,j:integer;
begin
for i:=0 to n-1 do
begin
write(' ',i,':');
for j:=1 to p[i,0] do
write(' ',p[i,j]);
writeln;
end;
end;
begin
readln(n);
for i:=0 to 25 do
for j:=1 to 25 do
p[i,j]:=0;
for i:=0 to n-1 do
begin
p[i,1]:=i;
p[i,0]:=1;
end;
while not (eof(input)) do
begin
readln(s);
if (pos('quit',s) <> 0) then
break;
ss:=copy(s,1,4);
analysis(s);
if (mf >= n) or (mt >= n) then
continue;
search(mf,fpos,fh);
search(mt,tpos,th);
if (fpos >= n) or (tpos >= n) or (fh = 0) or (th = 0) then continue;
if (fpos = tpos) or (mf = mt) then continue;
if (ss = 'move') and (fh = p[fpos,0]) then
if (sss = 'onto') and (th = p[tpos,0]) then
begin
p[tpos,0]:=p[tpos,0] + 1;
p[tpos, p[tpos,0]]:=p[fpos, p[fpos,0]];
p[fpos,0]:=p[fpos,0] - 1;
end
else
if (sss = 'over') then
begin
p[tpos,0]:=p[tpos,0] + 1;
p[tpos, p[tpos,0]]:=p[fpos, p[fpos,0]];
p[fpos,0]:=p[fpos,0] - 1;
end;
if (ss = 'pile') then
if (sss = 'onto') and (th = p[tpos,0]) then
begin
temp:=1+( p[fpos,0] - fh);
for i:=1 to temp do
begin
p[tpos,0]:=p[tpos,0] + 1;
p[tpos, p[tpos,0]]:=p[fpos, fh+i-1];
p[fpos,0]:=p[fpos,0] - 1;
end;
end
else
if (sss = 'over') then
begin
temp:=1+( p[fpos,0] - fh);
for i:=1 to temp do
begin
p[tpos,0]:=p[tpos,0] + 1;
p[tpos, p[tpos,0]]:=p[fpos, fh+i-1];
p[fpos,0]:=p[fpos,0] - 1;
end;
end;
end;
output;
end.
[/pascal]
hmm...
I have copied your source then compiled it and then tested on the sample input...
Your program answer was:
The same things happened to the other tests...
I don't know maybe it is my compilator failure but it also can be your program fault...
And what does your program give on your computer ??
Good Luck
I have copied your source then compiled it and then tested on the sample input...
Your program answer was:
and so on...0: 0
1: 1
...
The same things happened to the other tests...
I don't know maybe it is my compilator failure but it also can be your program fault...
And what does your program give on your computer ??
Good Luck

In my opinion the whole confusion is because you are assuming that there can be other blocks in a position while the original block itself is not there.
For example blocks 7 and 8 can be in the position of block 3 while block 3 is at that instant in another position, say in the position of block 2.
However, if you think about it, then with the given starting condition and the given operations, the above scenario is just not possible. Removing the code for that scenario should help.
For example blocks 7 and 8 can be in the position of block 3 while block 3 is at that instant in another position, say in the position of block 2.
However, if you think about it, then with the given starting condition and the given operations, the above scenario is just not possible. Removing the code for that scenario should help.
Problem 101 input problems
Please help me!
I am currently working on the 101 problem and am having a problem with the C++ iostream function cin.getline().
I believe that its from not clearing the input stream, but I don't know how one goes about doing this.
I first enter in the number of blocks
[cpp]int size;
cin >> size;[/cpp]
and then later when I want to take in the instruction as a single string
[cpp]char op[80];
cin.getline(op, 80);[/cpp]
This will not let the user do anything at all, and the debugger will just skip the line altogether.
If it is the first input line in the program it appears to work, so the clearing/flushing the input stream should solve this. If someone would like to tell me how.
I am currently working on the 101 problem and am having a problem with the C++ iostream function cin.getline().
I believe that its from not clearing the input stream, but I don't know how one goes about doing this.
I first enter in the number of blocks
[cpp]int size;
cin >> size;[/cpp]
and then later when I want to take in the instruction as a single string
[cpp]char op[80];
cin.getline(op, 80);[/cpp]
This will not let the user do anything at all, and the debugger will just skip the line altogether.
If it is the first input line in the program it appears to work, so the clearing/flushing the input stream should solve this. If someone would like to tell me how.
Please Help!
problem 101 - compile error... help me..
i received error message
***************************************
Here are the compiler error messages:
/tmp/cc9xBj1ymain.o: In function `main':
/tmp/ccpj56nDmain.i(.text+0x12): undefined reference to `_CL_4Main'
collect2: ld returned 1 exit status
***************************************
[/java]
import java.io.*;
import java.util.*;
class Prob_101_site
{
static String ReadLn (int maxLg) // utility function to read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";
try
{
while (lg < maxLg)
{
car = System.in.read();
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}
catch (IOException e)
{
return (null);
}
if ((car < 0) && (lg == 0)) return (null); // eof
return (new String (lin, 0, lg));
}
public static void main (String args[])
{
Prob_101_site myWork = new Prob_101_site();
myWork.Begin();
}
void Begin()
{
String line;
StringTokenizer idata;
int a, b, n;
int arr[][];
String op_1;
String op_2;
try
{
line = Prob_101_site.ReadLn(255);
idata = new StringTokenizer(line);
n = Integer.parseInt(idata.nextToken());
arr = new int[n][n];
/* initially array setting */
for (int i=0; i<=n-1; i++)
{
for (int j=0; j<=n-1; j++)
{
if (j==0) arr[j] = i;
else arr[j] = -1;
}
}
while ( (line = Prob_101_site.ReadLn(255)) != null)
{
idata = new StringTokenizer (line);
if( 1 == idata.countTokens()){
break;
} else{
op_1 = idata.nextToken();
a = Integer.parseInt (idata.nextToken());
op_2 = idata.nextToken();
b = Integer.parseInt (idata.nextToken());
int a_i = -1, a_j = -1, b_i = -1, b_j = -1, b_l = -1;
/* a, b의 위치 알아내기 */
for (int j=0; j<=n-1; j++)
{
for (int i=0; i<=n-1; i++)
{
if (a == arr[j])
{
a_i = i;
a_j = j;
}
if (b == arr[j])
{
b_i = i;
b_j = j;
}
if (a_i != -1 && b_i != -1)
{
i = n;
j = n;
}
}
}//end for
// [추가]만약 a와 b가 같은 array에 있으면.. 아무것도 안하기
if (a!=b && a_i!=b_i)
{
/* 연산 종류따라 수행하기 */
if (op_1.equals("move"))
{
for (int l=n-1; l>a_j; l--) //block a 위의 것 제자리로 옮기기
{
if (arr[a_i][l] != -1)
{
arr[a_i][0] = arr[a_i][l];
arr[a_i][l] = -1;
}
} //end for
if (op_2.equals("onto")) //block b 위의 것 제자리로 옮기기
{
for (int l=n-1; l>b_j; l--)
{
if (arr[b_i][l] != -1)
{
arr[b_i][0] = arr[b_i][l];
arr[b_i][l] = -1;
}
}
} //end if
for (int l=0; l<=n-1; l++) //block a를 block b의 위로 옮기기
{
if (arr[b_i][l] == -1)
{
arr[b_i][l] = arr[a_i][a_j];
arr[a_i][a_j] = -1;
}
}//end for
}//end if "move"
else if (op_1.equals("pile"))
{
if (op_2.equals("onto")) //block b 위의 것 제자리로 옮기기
{
for (int l=n-1; l>b_j; l--)
{
if (arr[b_i][l] != -1)
{
arr[b_i][0] = arr[b_i][l];
arr[b_i][l] = -1;
}
}
} //end if
for (int l=1; l<=n-1; l++) //block b위를 검색
{
if (arr[b_i][l] == -1) // block b의 null인 곳을 찾았으면,
{
b_l = l;
break;
}
} //end for
for (int m=a_j; m<=n-1; m++)
{
if (arr[a_i][m] != -1)
{
arr[b_i][b_l] = arr[a_i][m];
arr[a_i][m] = -1;
b_l++;
}
else if (arr[a_i][m] == -1) //다 옮겼음 나가기
{
m = n;
}
}// end for
}// end else if "pile"
} //end if
} //end else
}//end while
for(int i = 0; i < n; i++){
System.out.print(i+": ");
for(int j = 0; j < n; j++){
if(arr[j] != -1)
System.out.print(" "+arr[j]);
}
System.out.println();
}
// out.close();
}catch(Exception e) {System.out.println("error:" + e);}
}
}
************************************************************
i don't know what this message say.
please, help me..
***************************************
Here are the compiler error messages:
/tmp/cc9xBj1ymain.o: In function `main':
/tmp/ccpj56nDmain.i(.text+0x12): undefined reference to `_CL_4Main'
collect2: ld returned 1 exit status
***************************************
[/java]
import java.io.*;
import java.util.*;
class Prob_101_site
{
static String ReadLn (int maxLg) // utility function to read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";
try
{
while (lg < maxLg)
{
car = System.in.read();
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}
catch (IOException e)
{
return (null);
}
if ((car < 0) && (lg == 0)) return (null); // eof
return (new String (lin, 0, lg));
}
public static void main (String args[])
{
Prob_101_site myWork = new Prob_101_site();
myWork.Begin();
}
void Begin()
{
String line;
StringTokenizer idata;
int a, b, n;
int arr[][];
String op_1;
String op_2;
try
{
line = Prob_101_site.ReadLn(255);
idata = new StringTokenizer(line);
n = Integer.parseInt(idata.nextToken());
arr = new int[n][n];
/* initially array setting */
for (int i=0; i<=n-1; i++)
{
for (int j=0; j<=n-1; j++)
{
if (j==0) arr[j] = i;
else arr[j] = -1;
}
}
while ( (line = Prob_101_site.ReadLn(255)) != null)
{
idata = new StringTokenizer (line);
if( 1 == idata.countTokens()){
break;
} else{
op_1 = idata.nextToken();
a = Integer.parseInt (idata.nextToken());
op_2 = idata.nextToken();
b = Integer.parseInt (idata.nextToken());
int a_i = -1, a_j = -1, b_i = -1, b_j = -1, b_l = -1;
/* a, b의 위치 알아내기 */
for (int j=0; j<=n-1; j++)
{
for (int i=0; i<=n-1; i++)
{
if (a == arr[j])
{
a_i = i;
a_j = j;
}
if (b == arr[j])
{
b_i = i;
b_j = j;
}
if (a_i != -1 && b_i != -1)
{
i = n;
j = n;
}
}
}//end for
// [추가]만약 a와 b가 같은 array에 있으면.. 아무것도 안하기
if (a!=b && a_i!=b_i)
{
/* 연산 종류따라 수행하기 */
if (op_1.equals("move"))
{
for (int l=n-1; l>a_j; l--) //block a 위의 것 제자리로 옮기기
{
if (arr[a_i][l] != -1)
{
arr[a_i][0] = arr[a_i][l];
arr[a_i][l] = -1;
}
} //end for
if (op_2.equals("onto")) //block b 위의 것 제자리로 옮기기
{
for (int l=n-1; l>b_j; l--)
{
if (arr[b_i][l] != -1)
{
arr[b_i][0] = arr[b_i][l];
arr[b_i][l] = -1;
}
}
} //end if
for (int l=0; l<=n-1; l++) //block a를 block b의 위로 옮기기
{
if (arr[b_i][l] == -1)
{
arr[b_i][l] = arr[a_i][a_j];
arr[a_i][a_j] = -1;
}
}//end for
}//end if "move"
else if (op_1.equals("pile"))
{
if (op_2.equals("onto")) //block b 위의 것 제자리로 옮기기
{
for (int l=n-1; l>b_j; l--)
{
if (arr[b_i][l] != -1)
{
arr[b_i][0] = arr[b_i][l];
arr[b_i][l] = -1;
}
}
} //end if
for (int l=1; l<=n-1; l++) //block b위를 검색
{
if (arr[b_i][l] == -1) // block b의 null인 곳을 찾았으면,
{
b_l = l;
break;
}
} //end for
for (int m=a_j; m<=n-1; m++)
{
if (arr[a_i][m] != -1)
{
arr[b_i][b_l] = arr[a_i][m];
arr[a_i][m] = -1;
b_l++;
}
else if (arr[a_i][m] == -1) //다 옮겼음 나가기
{
m = n;
}
}// end for
}// end else if "pile"
} //end if
} //end else
}//end while
for(int i = 0; i < n; i++){
System.out.print(i+": ");
for(int j = 0; j < n; j++){
if(arr[j] != -1)
System.out.print(" "+arr[j]);
}
System.out.println();
}
// out.close();
}catch(Exception e) {System.out.println("error:" + e);}
}
}
************************************************************
i don't know what this message say.
please, help me..
101
This problem should be a easy one. But I alway got RE. I rewrite it several times and cannot get AC. Could someone help me?
[c]
#include<stdio.h>
#include<string.h>
int block[25][25],top[25],pos[25];
void unload(int);
void main(void)
{
int n,x,a,b,temp[25],count,t,y;
char com1[5],com2[5];
scanf("%d",&n);
for(x=0;x<n;x++)
block[x][0]=pos[x]=x,top[x]=0;
while(1)
{
scanf("%s",com1);
if(strcmp(com1,"quit")==0)
break;
scanf("%d",&a);
scanf("%s",com2);
scanf("%d",&b);
if(a==b || pos[a]==pos)
continue;
if(strcmp(com2,"onto")==0)
unload(b);
if(strcmp(com1,"move")==0)
{
unload(a);
t=block[pos[a]][top[a]--];
block[pos][++top[pos]]=t;
pos[a]=pos;
}
if(strcmp(com1,"pile")==0)
{
for(x=top[pos[a]],count=0;x>=0;x--)
if(block[pos[a]][x]!=a)
{
temp[count++]=block[pos[a]][x];
top[pos[a]]--;
}
else if(block[pos[a]][x]==a)
{
temp[count++]=block[pos[a]][x];
top[pos[a]]--;
break;
}
for(x=count-1;x>=0;x--)
{
t=temp[x];
block[pos][++top[pos]]=t;
pos[t]=pos;
}
}
}
for(x=0;x<n;x++)
{
printf("%d:",x);
if(top[x]>=0)
for(y=0;y<=top[x];y++)
printf(" %d",block[x][y]);
printf("\n");
}
}
void unload(int i)
{
int x,temp[25],count,t;
for(x=top[pos],count=0;x>=0;x--)
if(block[pos][x]!=i)
{
temp[count++]=block[pos][x];
top[pos]--;
}
else if(block[pos][x]==i)
break;
for(x=0;x<count;x++)
{
t=temp[x];
block[t][++top[t]]=t;
pos[t]=t;
}
}
[/c]
[c]
#include<stdio.h>
#include<string.h>
int block[25][25],top[25],pos[25];
void unload(int);
void main(void)
{
int n,x,a,b,temp[25],count,t,y;
char com1[5],com2[5];
scanf("%d",&n);
for(x=0;x<n;x++)
block[x][0]=pos[x]=x,top[x]=0;
while(1)
{
scanf("%s",com1);
if(strcmp(com1,"quit")==0)
break;
scanf("%d",&a);
scanf("%s",com2);
scanf("%d",&b);
if(a==b || pos[a]==pos)
continue;
if(strcmp(com2,"onto")==0)
unload(b);
if(strcmp(com1,"move")==0)
{
unload(a);
t=block[pos[a]][top[a]--];
block[pos][++top[pos]]=t;
pos[a]=pos;
}
if(strcmp(com1,"pile")==0)
{
for(x=top[pos[a]],count=0;x>=0;x--)
if(block[pos[a]][x]!=a)
{
temp[count++]=block[pos[a]][x];
top[pos[a]]--;
}
else if(block[pos[a]][x]==a)
{
temp[count++]=block[pos[a]][x];
top[pos[a]]--;
break;
}
for(x=count-1;x>=0;x--)
{
t=temp[x];
block[pos][++top[pos]]=t;
pos[t]=pos;
}
}
}
for(x=0;x<n;x++)
{
printf("%d:",x);
if(top[x]>=0)
for(y=0;y<=top[x];y++)
printf(" %d",block[x][y]);
printf("\n");
}
}
void unload(int i)
{
int x,temp[25],count,t;
for(x=top[pos],count=0;x>=0;x--)
if(block[pos][x]!=i)
{
temp[count++]=block[pos][x];
top[pos]--;
}
else if(block[pos][x]==i)
break;
for(x=0;x<count;x++)
{
t=temp[x];
block[t][++top[t]]=t;
pos[t]=t;
}
}
[/c]
[problem 101] i don't know what means this error message
i received error message
***************************************
Here are the compiler error messages:
/tmp/cc9xBj1ymain.o: In function `main':
/tmp/ccpj56nDmain.i(.text+0x12): undefined reference to `_CL_4Main'
collect2: ld returned 1 exit status
***************************************
[/java]
import java.io.*;
import java.util.*;
class Prob_101_site
{
static String ReadLn (int maxLg) // utility function to read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";
try
{
while (lg < maxLg)
{
car = System.in.read();
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}
catch (IOException e)
{
return (null);
}
if ((car < 0) && (lg == 0)) return (null); // eof
return (new String (lin, 0, lg));
}
public static void main (String args[])
{
Prob_101_site myWork = new Prob_101_site();
myWork.Begin();
}
void Begin()
{
String line;
StringTokenizer idata;
int a, b, n;
int arr[][];
String op_1;
String op_2;
try
{
line = Prob_101_site.ReadLn(255);
idata = new StringTokenizer(line);
n = Integer.parseInt(idata.nextToken());
arr = new int[n][n];
/* initially array setting */
for (int i=0; i<=n-1; i++)
{
for (int j=0; j<=n-1; j++)
{
if (j==0) arr[j] = i;
else arr[j] = -1;
}
}
while ( (line = Prob_101_site.ReadLn(255)) != null)
{
idata = new StringTokenizer (line);
if( 1 == idata.countTokens()){
break;
} else{
op_1 = idata.nextToken();
a = Integer.parseInt (idata.nextToken());
op_2 = idata.nextToken();
b = Integer.parseInt (idata.nextToken());
int a_i = -1, a_j = -1, b_i = -1, b_j = -1, b_l = -1;
for (int j=0; j<=n-1; j++)
{
for (int i=0; i<=n-1; i++)
{
if (a == arr[j])
{
a_i = i;
a_j = j;
}
if (b == arr[j])
{
b_i = i;
b_j = j;
}
if (a_i != -1 && b_i != -1)
{
i = n;
j = n;
}
}
}//end for
if (a!=b && a_i!=b_i)
{
if (op_1.equals("move"))
{
for (int l=n-1; l>a_j; l--)
{
if (arr[a_i][l] != -1)
{
arr[a_i][0] = arr[a_i][l];
arr[a_i][l] = -1;
}
} //end for
if (op_2.equals("onto"))
{
for (int l=n-1; l>b_j; l--)
{
if (arr[b_i][l] != -1)
{
arr[b_i][0] = arr[b_i][l];
arr[b_i][l] = -1;
}
}
} //end if
for (int l=0; l<=n-1; l++)
{
if (arr[b_i][l] == -1)
{
arr[b_i][l] = arr[a_i][a_j];
arr[a_i][a_j] = -1;
}
}//end for
}//end if "move"
else if (op_1.equals("pile"))
{
if (op_2.equals("onto"))
{
for (int l=n-1; l>b_j; l--)
{
if (arr[b_i][l] != -1)
{
arr[b_i][0] = arr[b_i][l];
arr[b_i][l] = -1;
}
}
} //end if
for (int l=1; l<=n-1; l++)
{
if (arr[b_i][l] == -1)
{
b_l = l;
break;
}
} //end for
for (int m=a_j; m<=n-1; m++)
{
if (arr[a_i][m] != -1)
{
arr[b_i][b_l] = arr[a_i][m];
arr[a_i][m] = -1;
b_l++;
}
else if (arr[a_i][m] == -1)
{
m = n;
}
}// end for
}// end else if "pile"
} //end if
} //end else
}//end while
for(int i = 0; i < n; i++){
System.out.print(i+": ");
for(int j = 0; j < n; j++){
if(arr[j] != -1)
System.out.print(" "+arr[j]);
}
System.out.println();
}
// out.close();
}catch(Exception e) {System.out.println("error:" + e);}
}
}
************************************************************
i don't know what this message say.
please, help me..
***************************************
Here are the compiler error messages:
/tmp/cc9xBj1ymain.o: In function `main':
/tmp/ccpj56nDmain.i(.text+0x12): undefined reference to `_CL_4Main'
collect2: ld returned 1 exit status
***************************************
[/java]
import java.io.*;
import java.util.*;
class Prob_101_site
{
static String ReadLn (int maxLg) // utility function to read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";
try
{
while (lg < maxLg)
{
car = System.in.read();
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}
catch (IOException e)
{
return (null);
}
if ((car < 0) && (lg == 0)) return (null); // eof
return (new String (lin, 0, lg));
}
public static void main (String args[])
{
Prob_101_site myWork = new Prob_101_site();
myWork.Begin();
}
void Begin()
{
String line;
StringTokenizer idata;
int a, b, n;
int arr[][];
String op_1;
String op_2;
try
{
line = Prob_101_site.ReadLn(255);
idata = new StringTokenizer(line);
n = Integer.parseInt(idata.nextToken());
arr = new int[n][n];
/* initially array setting */
for (int i=0; i<=n-1; i++)
{
for (int j=0; j<=n-1; j++)
{
if (j==0) arr[j] = i;
else arr[j] = -1;
}
}
while ( (line = Prob_101_site.ReadLn(255)) != null)
{
idata = new StringTokenizer (line);
if( 1 == idata.countTokens()){
break;
} else{
op_1 = idata.nextToken();
a = Integer.parseInt (idata.nextToken());
op_2 = idata.nextToken();
b = Integer.parseInt (idata.nextToken());
int a_i = -1, a_j = -1, b_i = -1, b_j = -1, b_l = -1;
for (int j=0; j<=n-1; j++)
{
for (int i=0; i<=n-1; i++)
{
if (a == arr[j])
{
a_i = i;
a_j = j;
}
if (b == arr[j])
{
b_i = i;
b_j = j;
}
if (a_i != -1 && b_i != -1)
{
i = n;
j = n;
}
}
}//end for
if (a!=b && a_i!=b_i)
{
if (op_1.equals("move"))
{
for (int l=n-1; l>a_j; l--)
{
if (arr[a_i][l] != -1)
{
arr[a_i][0] = arr[a_i][l];
arr[a_i][l] = -1;
}
} //end for
if (op_2.equals("onto"))
{
for (int l=n-1; l>b_j; l--)
{
if (arr[b_i][l] != -1)
{
arr[b_i][0] = arr[b_i][l];
arr[b_i][l] = -1;
}
}
} //end if
for (int l=0; l<=n-1; l++)
{
if (arr[b_i][l] == -1)
{
arr[b_i][l] = arr[a_i][a_j];
arr[a_i][a_j] = -1;
}
}//end for
}//end if "move"
else if (op_1.equals("pile"))
{
if (op_2.equals("onto"))
{
for (int l=n-1; l>b_j; l--)
{
if (arr[b_i][l] != -1)
{
arr[b_i][0] = arr[b_i][l];
arr[b_i][l] = -1;
}
}
} //end if
for (int l=1; l<=n-1; l++)
{
if (arr[b_i][l] == -1)
{
b_l = l;
break;
}
} //end for
for (int m=a_j; m<=n-1; m++)
{
if (arr[a_i][m] != -1)
{
arr[b_i][b_l] = arr[a_i][m];
arr[a_i][m] = -1;
b_l++;
}
else if (arr[a_i][m] == -1)
{
m = n;
}
}// end for
}// end else if "pile"
} //end if
} //end else
}//end while
for(int i = 0; i < n; i++){
System.out.print(i+": ");
for(int j = 0; j < n; j++){
if(arr[j] != -1)
System.out.print(" "+arr[j]);
}
System.out.println();
}
// out.close();
}catch(Exception e) {System.out.println("error:" + e);}
}
}
************************************************************
i don't know what this message say.
please, help me..
The class name MUST be Main ...
Check out this page: http://acm.uva.es/problemset/howtows.html#java and http://acm.uva.es/problemset/java.html

Check out this page: http://acm.uva.es/problemset/howtows.html#java and http://acm.uva.es/problemset/java.html
I couldn't underwstand why i should i think the way tiwari ji has told me.....
My prog is acting acoording to the input.....
Even if what tiwari ji has told is true i don't see where my prog contradicts his argument.......
Can any one give me a sample input where my prog fails to run.....
i have already given my prog in this thread....
My prog is acting acoording to the input.....
Even if what tiwari ji has told is true i don't see where my prog contradicts his argument.......
Can any one give me a sample input where my prog fails to run.....
i have already given my prog in this thread....