eolymp
bolt
Try our new interface for solving problems
published at 4/17/15, 3:17:21 pm

Вагон, що приходить із A їде до B в оберненому напрямку? Якщо так, то можливо у тестах є в кінці два '\n'?

published at 4/3/24, 2:16:28 am

import java.util.Scanner; import java.util.Vector;

public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (true) { int n = scanner.nextInt(); if (n == 0) break; scanner.nextLine(); // Consume newline character String s = scanner.nextLine(); while (!s.equals("0")) { Vector<Integer> stalemate = new Vector<>(); Scanner stream = new Scanner(s); int number; while (stream.hasNextInt()) { number = stream.nextInt(); for (int i = 1; i <= n; i++) { stalemate.add(i); while (!stalemate.isEmpty() && number == stalemate.lastElement()) { stalemate.remove(stalemate.size() - 1); if (stream.hasNextInt()) { number = stream.nextInt(); } } } } System.out.println(stalemate.isEmpty() ? "Yes" : "No"); s = scanner.nextLine(); } System.out.println(); } } }