QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#873930#3445. Numbers On a Treefernandes_queilaCompile Error//Java173.4kb2025-01-27 09:17:482025-01-27 09:17:49

Judging History

你现在查看的是最新测评结果

  • [2025-01-27 09:17:49]
  • 评测
  • [2025-01-27 09:17:48]
  • 提交

answer

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in); 
        // L\xea a entrada do usu\xe1rio
        String line = scanner.nextLine().trim();
        String[] parts = line.split(" ");

        int height = Integer.parseInt(parts[0]);
        String road = parts.length > 1 ? parts[1] : "";

        BinaryTree binaryTree = new BinaryTree();
        binaryTree.constructTree(height);

        int result = binaryTree.searchNode(height, road);
        System.out.println(result);

        scanner.close(); 
    }
}

class TreeNode {
    int value;
    TreeNode left, right;

    TreeNode(int value) {
        this.value = value;
        this.left = this.right = null;
    }
}

class BinaryTree {
    private TreeNode root;

    public void constructTree(int height) {
        int totalNodes = (1 << (height + 1)) - 1;
        root = buildTree(1, totalNodes);
    }

    private TreeNode buildTree(int start, int end) {
        if (start > end) return null;
        int mid = (start + end) / 2;
        TreeNode node = new TreeNode(mid);
        node.left = buildTree(start, mid - 1);
        node.right = buildTree(mid + 1, end);
        return node;
    }

    public int searchNode(int height, String road) {
        int rootLabel = (1 << (height + 1)) - 1;

        if (road.isEmpty()) {
            return rootLabel;
        }

        int label = rootLabel;
        int local = 0;

        for (char move : road.toCharArray()) {
            if (Character.toLowerCase(move) == 'l') {
                local = 2 * local + 1;
            } else if (Character.toLowerCase(move) == 'r') {
                local = 2 * local + 2;
            }
        }

        label -= local;
        return label;
    }
}
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // L\xea a entrada do usu\xe1rio
        String line = scanner.nextLine().trim();
        String[] parts = line.split(" ");

        int height = Integer.parseInt(parts[0]); 
        String road = parts.length > 1 ? parts[1] : ""; 

        BinaryTree binaryTree = new BinaryTree(); 
        binaryTree.constructTree(height); 
        int result = binaryTree.searchNode(height, road);
        System.out.println(result);

        scanner.close(); 
    }
}

class TreeNode {
    int value;
    TreeNode left, right;

    TreeNode(int value) {
}

class BinaryTree {
    private TreeNode root;

    public void constructTree(int height) {
        int totalNodes = (1 << (height + 1)) - 1;
        root = buildTree(1, totalNodes);
    }

    private TreeNode buildTree(int start, int end) {
        if (start > end) return null;
        int mid = (start + end) / 2;
        TreeNode node = new TreeNode(mid);
        node.left = buildTree(start, mid - 1);
        node.right = buildTree(mid + 1, end);
        return node;
    }

    public int searchNode(int height, String road) {
        int rootLabel = (1 << (height + 1)) - 1;

        if (road.isEmpty()) {
            return rootLabel;
        }

        int label = rootLabel;
        int local = 0;

        for (char move : road.toCharArray()) {
            if (Character.toLowerCase(move) == 'l') {
                local = 2 * local + 1;
            } else if (Character.toLowerCase(move) == 'r') {
                local = 2 * local + 2;
            }
        }

        label -= local;
        return label;
    }
}

詳細信息

Main.java:7: error: unmappable character (0xEA) for encoding UTF-8
        // L� a entrada do usu�rio
            ^
Main.java:7: error: unmappable character (0xE1) for encoding UTF-8
        // L� a entrada do usu�rio
                              ^
Main.java:79: error: unmappable character (0xEA) for encoding UTF-8
        // L� a entrada do usu�rio
            ^
Main.java:79: error: unmappable character (0xE1) for encoding UTF-8
        // L� a entrada do usu�rio
                              ^
Main.java:73: error: class, interface, enum, or record expected
import java.util.Scanner;
^
Main.java:140: error: reached end of file while parsing
}
 ^
6 errors