QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#874533#3445. Numbers On a Treefernandes_queilaCompile Error//C++111.4kb2025-01-28 10:32:572025-01-28 10:33:03

Judging History

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

  • [2025-01-28 10:33:03]
  • 评测
  • [2025-01-28 10:32:57]
  • 提交

answer

using System;

class TreeNode
{
    public int Label { get; set; }
    public TreeNode Left { get; set; }
    public TreeNode Right { get; set; }

    public TreeNode(int label)
    {
        Label = label;
        Left = null;
        Right = null;
    }
}

class Program
{
    static TreeNode BuildTree(int height, ref int currentLabel)
    {
        if (height < 0)
            return null;

        TreeNode node = new TreeNode(currentLabel);
        currentLabel--;

        node.Right = BuildTree(height - 1, ref currentLabel);
        node.Left = BuildTree(height - 1, ref currentLabel);

        return node;
    }

    static int SearchNode(TreeNode root, string road)
    {
        TreeNode currentNode = root;

        foreach (char move in road)
        {
            if (char.ToLower(move) == 'l')
            {
                currentNode = currentNode.Left;
            }
            else if (char.ToLower(move) == 'r')
            {
                currentNode = currentNode.Right;
            }
        }

        return currentNode.Label;
    }

    static void Main()
    {
        string line = Console.ReadLine().Trim();
        string[] parts = line.Split();
        
        int height = int.Parse(parts[0]);
        string road = parts.Length > 1 ? parts[1] : "";

        int currentLabel = (int)Math.Pow(2, height + 1) - 1;
        TreeNode root = BuildTree(height, ref currentLabel);

        Console.WriteLine(SearchNode(root, road));
    }
}

Details

answer.code:1:7: error: expected nested-name-specifier before ‘System’
    1 | using System;
      |       ^~~~~~
answer.code:5:11: error: expected ‘:’ before ‘int’
    5 |     public int Label { get; set; }
      |           ^~~~
      |           :
answer.code:5:34: error: expected ‘;’ at end of member declaration
    5 |     public int Label { get; set; }
      |                                  ^
      |                                   ;
answer.code:6:11: error: expected ‘:’ before ‘TreeNode’
    6 |     public TreeNode Left { get; set; }
      |           ^~~~~~~~~
      |           :
answer.code:6:21: error: field ‘Left’ has incomplete type ‘TreeNode’
    6 |     public TreeNode Left { get; set; }
      |                     ^~~~
answer.code:3:7: note: definition of ‘class TreeNode’ is not complete until the closing brace
    3 | class TreeNode
      |       ^~~~~~~~
answer.code:6:38: error: expected ‘;’ at end of member declaration
    6 |     public TreeNode Left { get; set; }
      |                                      ^
      |                                       ;
answer.code:7:11: error: expected ‘:’ before ‘TreeNode’
    7 |     public TreeNode Right { get; set; }
      |           ^~~~~~~~~
      |           :
answer.code:7:21: error: field ‘Right’ has incomplete type ‘TreeNode’
    7 |     public TreeNode Right { get; set; }
      |                     ^~~~~
answer.code:3:7: note: definition of ‘class TreeNode’ is not complete until the closing brace
    3 | class TreeNode
      |       ^~~~~~~~
answer.code:7:39: error: expected ‘;’ at end of member declaration
    7 |     public TreeNode Right { get; set; }
      |                                       ^
      |                                        ;
answer.code:9:11: error: expected ‘:’ before ‘TreeNode’
    9 |     public TreeNode(int label)
      |           ^~~~~~~~~
      |           :
answer.code:15:2: error: expected ‘;’ after class definition
   15 | }
      |  ^
      |  ;
answer.code:5:24: error: ‘get’ was not declared in this scope
    5 |     public int Label { get; set; }
      |                        ^~~
answer.code:5:27: error: expected ‘}’ before ‘;’ token
    5 |     public int Label { get; set; }
      |                           ^
answer.code:5:22: note: to match this ‘{’
    5 |     public int Label { get; set; }
      |                      ^
answer.code:5:27: error: cannot convert ‘<brace-enclosed initializer list>’ to ‘int’ in initialization
    5 |     public int Label { get; set; }
      |                           ^
answer.code:5:27: error: expected ‘;’ before ‘;’ token
answer.code: In constructor ‘TreeNode::TreeNode(int)’:
answer.code:12:16: error: ‘null’ was not declared in this scope
   12 |         Left = null;
      |                ^~~~
answer.code: At global scope:
answer.code:19:43: error: ‘ref’ has not been declared
   19 |     static TreeNode BuildTree(int height, ref int currentLabel)
      |                                           ^~~
answer.code:19:43: error: two or more data types in declaration of ‘currentLabel’
answer.code:33:42: error: ‘string’ has not been declared
   33 |     static int SearchNode(TreeNode root, string road)
      |                                          ^~~~~~
answer.code:65:2: error: expected ‘;’ after class definition
   65 | }
      |  ^
      |  ;
answer.code: In static member function ‘static TreeNode Program::BuildTree(...)’:
answer.code:21:13: error: ‘height’ was not declared in this scope
   21 |         if (height < 0)
      |             ^~~~~~
answer.code:22:20: error: ‘null’ was not declared in this scope
   22 |             return null;
      |                    ^~~~
answer.code:24:38: error: ‘currentLabel’ was not declared in this scope
   24 |         TreeNode node = new TreeNode(currentLabel);
      |                                      ^~~~~~~~~~~~
answer.code:27:32: error: ‘height’ was not declared in this scope
   27 |         node.Right = BuildTree(height - 1, ref currentLabel);
      |                                ^~~~~~
answer.code:27:44: error: ‘ref’ was not declared in this scope
   27 |         node.Right = BuildTree(height - 1, ref currentLabel);
      |                                            ^~~
answer.code:28:47: error: expected ‘)’ before ‘currentLabel’
   28 |         node.Left = BuildTree(height - 1, ref currentLabel);
      |                                               ^~~~~~~~~~~~
answer.code:28:30: note: to match this ‘(’
   28 |         node.Left = BuildTree(height - 1, ref currentLabel);
      |                              ^
answer.code: In static member function ‘static int Program::SearchNode(TreeNode, int)’:
answer.code:37:18: error: expected primary-expression before ‘char’
   37 |         foreach (char move in road)
      |                  ^~~~
answer.code:37:9: error: ‘foreach’ was not declared in this scope
   37 |         foreach (char move in road)
      |         ^~~~~~~
answer.code: In static member function ‘...