#Not intended output

1 messages · Page 1 of 1 (latest)

neat nacelle
#
import java.util.*;
import java.io.*;
public class Mowing{
    
    public static class Point{
        int x , y;
        Point( int x , int y){
            this.x = x;
            this.y = y;
        }
        public int hashCode() {
            return Objects.hash(x,y);
        }
        public boolean equals(Object other) {
            Point temp = (Point)other;
            return temp.x==x && temp.y ==y;
        }
        public String toString() {
            return String.format("%d %d", x,y);
        }
    }
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(new FileReader("mowing.in"));
        PrintWriter out = new PrintWriter(new FileWriter("mowing.out"));
        int num = Integer.valueOf(in.nextLine());
        int max = Integer.MAX_VALUE;
        HashMap<Point , Integer> grid = new HashMap<>();
        int x = 0, y= 0,time = 0;
        grid.put(new Point(x,y), 0);
        for(int i = 0;i<num;i++) {
            String direction = in.next();
            int steps = Integer.valueOf(in.nextLine().trim());
            for(int j = 0;j<steps;j++) {
                if(direction.equals("N"))y++;
                if(direction.equals("E"))x++;
                if(direction.equals("S"))y--;
                if(direction.equals("W"))x--;
                time++;
                if(grid.containsKey(new Point(x,y))) {
                    max = Math.min(max, time-grid.get(new Point(x,y)));
                }
                grid.put(new Point(x,y),time);
            }
        }
        out.println(max);
        System.out.println(grid);
        out.close();
        

    }

}

This fails a few test cases and I am not sure why. PLease let me know if you find anything!

frozen patioBOT
#

<@&987246717831381062> please have a look, thanks.

frozen patioBOT
# neat nacelle ```java import java.util.*; import java.io.*; public class Mowing{ publ...

Detected code, here are some useful tools:

Formatted code
import java.util. * ;
import java.io. * ;

public class Mowing {
  public static class Point {
    int x, y;
    Point(int x, int y) {
      this .x = x;
      this .y = y;
    }
    public int hashCode() {
      return Objects.hash(x, y);
    }
    public boolean equals(Object other) {
      Point temp = (Point) other;
      return temp.x == x && temp.y == y;
    }
    public String toString() {
      return String.format("%d %d", x, y);
    }
  }
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(new FileReader("mowing.in"));
    PrintWriter out = new PrintWriter(new FileWriter("mowing.out"));
    int num = Integer.valueOf(in.nextLine());
    int max = Integer.MAX_VALUE;
    HashMap<Point, Integer> grid = new HashMap<>();
    int x = 0, y = 0, time = 0;
    grid.put(new Point(x, y), 0);
    for (int i = 0; i < num; i++) {
      String direction = in.next();
      int steps = Integer.valueOf(in.nextLine().trim());
      for (int j = 0; j < steps; j++) {
        if (direction.equals("N")) y++;
        if (direction.equals("E")) x++;
        if (direction.equals("S")) y--;
        if (direction.equals("W")) x--;
        time++;
        if (grid.containsKey(new Point(x, y))) {
          max = Math.min(max, time - grid.get(new Point(x, y)));
        }
        grid.put(new Point(x, y), time);
      }
    }
    out.println(max);
    System.out.println(grid);
    out.close();
  }
}
frozen patioBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If your code is long, or you have multiple files to share, consider posting it on sites like https://pastebin.com/ and share the link instead, that is easier to browse for helpers.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

slender igloo
#

@neat nacelle print out direction

neat nacelle
#

I did, it looks fine

slender igloo
#

See if it is what you expect

#

Ok

neat nacelle
#

I forgot to print -1

#

😭

#

if he never visits a spot

#

thats why you have to read the instructions 💀

#

ty!

frozen patioBOT
#

Closed the thread.

slender igloo
#

Lmao I was just reading through it now well glad you solved it

neat nacelle