Page 4 of 5
118 : I am getting mad
Posted: Wed Aug 23, 2006 6:26 pm
by phonix
I tested my program with all samples on the board and it work correctly. but i still getting WA. can somebody help me and tell me why????
this is my code:
Code: Select all
#include <iostream.h>
#include <string.h>
int n,m,x,y,d[3];
char movelist[200];
bool scent[51][51];
char direction()
{
if (d[1]== 1)
return 'N';
else if (d[1]==-1)
return 'S';
else if (d[0]== 1)
return 'E';
else
return 'W';
}
bool move(char mo)
{
int temp;
bool sw=true;
if (mo=='F')
{
x+=d[0];
y+=d[1];
if (x>n||x<0||y<0||y>m)
{
x-=d[0];
y-=d[1];
if (scent[x][y])
{
scent[x][y]=false;
sw=false;
}
}
}
else if (mo=='R')
{
temp=d[0];
d[0]=d[1];
d[1]=-temp;
}
else if (mo=='L')
{
temp=d[1];
d[1]=d[0];
d[0]=-temp;
}
return sw;
}
void main()
{
int i,j;
char dir;
bool sw;
for (i=0;i<51;i++)
for (j=0;j<51;j++)
scent[i][j]=true;
cin >>n>>m;
while (cin>>x>>y>>dir)
{
if (dir=='N') {d[0]= 0;d[1]= 1;}
else if(dir=='E') {d[0]= 1;d[1]= 0;}
else if(dir=='S') {d[0]= 0;d[1]=-1;}
else if(dir=='W') {d[0]=-1;d[1]= 0;}
cin.getline(movelist,100,'\n');
cin.getline(movelist,100,'\n');
sw=true;
for (i=0;i<strlen(movelist)&&sw;i++)
sw=move(movelist[i]);
if (sw)
cout<<x<<" "<<y<<" "<<direction()<<endl;
else
cout<<x<<" "<<y<<" "<<direction()<<" LOST\n";
}
}
i think it's because of my nationality. iran is sanctioned by america so iranian code r not working correct

Output limit exited!~
Posted: Thu Nov 16, 2006 2:09 pm
by smilitude
:S i am getting output limit exited.. how could that happen to this simple code
:(
Posted: Fri Nov 17, 2006 11:12 am
by smilitude
i got output limit exited cause i wrote
Code: Select all
while(scanf("%d %d %c",¤t.x,¤t.y,&ch)) {
instead of
Code: Select all
while(scanf("%d %d %c",¤t.x,¤t.y,&ch)==3) {
thats all...
Posted: Sat Dec 02, 2006 11:46 am
by razor_blue
I've tried the input above and compared to the lantimilan's output.
It's absolutely identical, so I'm very confused why my code is wrong.
Does someone can help?
Posted: Sun Dec 03, 2006 2:46 am
by Jan
I think you havent understood the 'scent' properly. The problem states
lost robots leave a robot ``scent'' that prohibits future robots from dropping off the world at the same grid point
Check the samples...
Input:
Output:
Because the first robot is dropped off from (0,0) and thus leaves a 'scent', the second robot sees the 'scent' in (0,0) and so it remains in the grid. Hope it helps.
Posted: Mon Dec 04, 2006 3:46 am
by razor_blue
Thank you Jan, now I understand the problem and I got AC.
Posted: Mon Apr 16, 2007 7:09 am
by joebin
i tried above all , but i got WA , either.
following is my code :
Code: Select all
#include<iostream>
using namespace std;
int main( int argc, char * argv[] )
{
int a,i,j,m,n,l[51][51],x,y,p[4]={1,1,-1,-1};
char k,d[4]={'N','E','S','W'},t[100];
cin >>m>>n;
for(i=0;i<=m;i++)
for(j=0;j<=n;j++)
l[i][j]=1;
while(cin >>x>>y>>k!=NULL){
j=0;i=0;a=1;
while(d[j]!=k)
j++;
cin.getline(t,100);cin.getline(t,100);
while(t[i]!='\0'){
if(t[i]=='F'){
if(j%2==0)
y+=p[j];
else
x+=p[j];
}
if(t[i]=='R')
j=(j+1)%4;
if(t[i]=='L')
j=(j+3)%4;
i++;
if(x>m||y>n||x<0||y<0){
if((j%2==0&&l[x][y-p[j]]==0)||(j%2==1&&l[x-p[j]][y]==0)){
if(j%2==0)
y-=p[j];
else
x-=p[j];
}
else{
a=0;
if(j%2==0)
y-=p[j];
else
x-=p[j];
l[x][y]=0;
cout <<x<<" "<<y<<" "<<d[j]<<" LOST"<<endl;
break;
}
}
}
if(a==1)
cout <<x<<" "<<y<<" "<<d[j]<<endl;
}
return 0;
}
could anyone tell me why ?? THX!!
WA...help
Posted: Tue Mar 04, 2008 2:35 am
by gareve25
my code works with that big input, but im still getting WA, can someone tell me why...
I try and try this problem, for a long time, and my two errors are this:
-If the robor fall in a corner the signal have effect on 1 or 2 or 3 or 4 squares
- a newline at the end of output(!!!!!!!!!! mi long time error, frustating);
Re: 118 WA: wtf
Posted: Wed Jul 30, 2008 9:05 pm
by amr saqr
There is a mistake in the problem description
All instruction strings will be less than 100 characters in length.
when i submitted my code with a 100 char array it gave me WA, and when i changed it to 101 with the same logic it was AC
be careful ...
Re: 118 WA: wtf
Posted: Thu Jul 31, 2008 11:05 am
by Obaida
There is no fault in the program description.
For a 100 length string you can't get Accepted by a 100 SIZE array.(Think why

).
You will get the answer.
Re: 118 WA: wtf
Posted: Thu Jul 31, 2008 11:26 am
by amr saqr
Again

,
All instruction strings will be
less than 100 characters in length.
less less less less less
that means that there will be 99 instructions at maximum not 100, so it's enough to make an array of 100 characters, 99 for the instructions and an extra char for the null character, but the 100 array didn't work, when i changed it to 101 i got AC, that's why i said there is a mistake in the problem description

.
Re: 118 WA: wtf
Posted: Mon Nov 03, 2008 7:48 am
by sakhassan
Getting WA

.. is my logic wrong

... Please help me. This is ma code:
Code: Select all
#include<stdio.h>
#define N 102
int cur_x,cur_y;
int scent[N][N];
void forward(char d)
{
if(d=='W')
cur_x -=1;
else if(d=='E')
cur_x += 1;
else if(d=='N')
cur_y += 1;
else
cur_y -= 1;
}
char move_dir(char d,char m)
{
if(m=='L')
{
if(d=='W')
return 'S';
else if(d=='S')
return 'E';
else if(d=='E')
return 'N';
else if(d=='N')
return 'W';
}
else
{
if(d=='W')
return 'N';
else if(d=='N')
return 'E';
else if(d=='E')
return 'S';
else if(d=='S')
return 'W';
}
}
int main()
{
int n,m;
int x,y;
char d;
char str[N],dir[N];
char ch;
int flag;
int temp_x,temp_y;
char cur_d;
int i;
scanf("%d%d",&n,&m);
gets(str);
while(gets(str))
{
sscanf(str,"%d %d %c",&x,&y,&d);
gets(dir);
cur_x = x;
cur_y = y;
cur_d = d;
flag = 1;
for(i=0;dir[i];i++)
{
ch = dir[i];
if(ch=='F')
{
temp_x = cur_x;
temp_y = cur_y;
forward(cur_d);
if(scent[cur_x][cur_y] || (cur_x<0 || cur_y<0) )
{
cur_x = temp_x;
cur_y = temp_y;
}
}
else
cur_d = move_dir(cur_d,ch);
if( cur_x >= (n-1) || cur_y>= (m-1))
{
flag = 0;
scent[cur_x][cur_y] = 1;
break;
}
}
printf("%d %d %c",cur_x,cur_y,cur_d);
if(!flag)
printf(" LOST");
printf("\n");
}
return 0;
}
To "sakhassan".
Posted: Tue Nov 04, 2008 12:51 pm
by porker2008
Your solution even can not handle the example input!!!
Sample input:
Code: Select all
5 3
1 1 E
RFRFRFRF
3 2 N
FRRFLLFFRRFLL
0 3 W
LLFFFLFLFL
Sample output:
Your code produces:
Please check your program. If the preview robots leave a "scent" on a block, the latter robots cannot leave the board from that block any more.
When the robots meet a block that have a scent on it and the next action will make the robots lost, you should ignore the action and check the next action until all the action are acted or ignored.
BTW, you can use integers to recognize the dirctions instead of using characters.
For instance, you can use 0 for N, 1 for E, 2 for S and 3 for W.
When you meet a "L", you can change the dirction from i to (i+3)%4.
When you meet a "R", you can change the dirction from i to (i+1)%4.
That can make you handle the direction more easily.
118 - RE
Posted: Wed Jul 14, 2010 5:55 pm
by peratu
Hi.
I have made
this problem using java language, and the judge always give me a Runtime Error.
I have tested my program with a lot of input tests cases, and the results are correct, because I check them on
UVA toolkit.
I don't know where the problem is. Here is my code:
#### EDITED ####
I have got AC changing the name of the main class to Main , and changing some functions like this:
public static void processInstruction()
to:
static void processInstruction()
(just remove "public" keyword)
###############
Java runtime error problem 118
Posted: Sun Oct 03, 2010 3:54 am
by matt123437
I'm new to coding in java on the UVA judge. I seem to be getting the correct output from my code but I'm getting a runtime error when I submit to the judge. I'm also not sure if I'm checking for EOF in the correct manner(scan.hasNextLine()). Here is my code
Code: Select all
import java.util.*;
/**
*
*
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int x_max = 0;
int y_max = 0;
int x =0;
int y =0;
boolean no_lost = true;
boolean[][]scent;
String orien = "";
String moves = "";
Scanner scan = new Scanner(System.in);
//get max vals
x_max = scan.nextInt();
y_max = scan.nextInt();
scent = new boolean[x_max+2][y_max+2];
while(scan.hasNextInt()){
x = scan.nextInt();
y = scan.nextInt();
orien = scan.next();
scan.nextLine();
moves = scan.nextLine();
for(int i=0;i<moves.length();i++){
if(moves.substring(i, i+1).equals("R")){
if(orien.equals("N"))orien="E";
else if(orien.equals("S"))orien = "W";
else if(orien.equals("E"))orien = "S";
else if(orien.equals("W"))orien = "N";
}
if(moves.substring(i, i+1).equals("L")){
if(orien.equals("N"))orien="W";
else if(orien.equals("S"))orien="E";
else if(orien.equals("E"))orien="N";
else if(orien.equals("W"))orien="S";
}
if(moves.substring(i, i+1).equals("F")){
if(orien.equals("N"))y++;
else if(orien.equals("S"))y--;
else if(orien.equals("E"))x++;
else if(orien.equals("W"))x--;
}
if((y > y_max || x > x_max)||(y<0||x<0)){
if(scent[x][y]==true){
if(y>y_max)y--;
if(x>x_max)x--;
}
else{
if(y >y_max){
scent[x][y]=true;
y=y_max;
}
if(x >x_max){
scent[x][y]=true;
x=x_max;
}
System.out.println(x+" "+y+" "+orien+" LOST");
no_lost = false;
i = moves.length();
}
}
}
if(no_lost) System.out.println(x+" "+y+" "+orien);
no_lost = true;
}
}
}
Thanks