Submission details
Task:Tulkki
Sender:rendes
Submission time:2025-10-28 20:29:14 +0200
Language:C++ (C++20)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3details
#20.00 s1, 2, 3details
#30.00 s1, 2, 3details
#4ACCEPTED0.00 s1, 2, 3details
#5ACCEPTED0.01 s1, 2, 3details
#6ACCEPTED0.01 s1, 2, 3details
#70.00 s2, 3details
#80.00 s2, 3details
#90.00 s2, 3details
#100.00 s2, 3details
#110.00 s2, 3details
#120.00 s2, 3details
#130.00 s3details
#140.00 s3details
#150.00 s3details
#160.00 s3details
#170.00 s3details
#180.00 s3details

Compiler report

input/code.cpp: In member function 'void Interpreter::GetCommandBounds(std::string, int&, int&)':
input/code.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i = 0; i < in.length(); i++) { // remove spaces
      |                     ~~^~~~~~~~~~~~~
input/code.cpp: In member function 'void Interpreter::ProcessLine(std::string)':
input/code.cpp:48:9: warning: unused variable 'leftoff' [-Wunused-variable]
   48 |     int leftoff = 0;
      |         ^~~~~~~

Code

#include <cstring>
#include <iostream>
#include <string>

class NumberManager {
  uint *varvals; // 26 elements
public:
  NumberManager() {
    varvals = new uint[26];
    std::memset(varvals, 0, 26 * sizeof(int));
  }
  ~NumberManager() { delete[] varvals; }
  uint &GetVal(char c) { return varvals[c - 'A']; }
  void IncVal(char c) { GetVal(c) += 1; }
  void ResVal(char c) { GetVal(c) = 0; }
};

class Interpreter {
  NumberManager nm;

public:
  void GetCommandBounds(std::string in, int& a, int& b) { // sunk-cost
    a = 0;
    b=0;
    for (int i = 0; i < in.length(); i++) { // remove spaces
      a=i;
      if (in[i] == ' ')
        continue;
      else
	break;
    }

    for (int i = in.length(); i > 0; i--) { // remove spaces
      b=i;
      if (in[i-1] == ' ')
        continue;
      else if (in[i - 1] == ')') {
        b--;
	break;
        }	
      else 
	break;
    }


  }
  void ProcessLine(std::string line) {
    int leftoff = 0;

    while (line[0] == ' ') {
      line.erase(0, 1);
    }

    //std::cout << "processing line: \"" << line << "\" \n";

    if (line[0] == '#') { // skip commented line
      return;
    } else if (line[0] == 'C') {
      nm.ResVal(line[6]);
      line.erase(0,8);
    } else if (line[0] == 'I') {
      nm.IncVal(line[9]);
      line.erase(0, 10);
    } else if (line[0] == 'P') {
      std::cout << nm.GetVal(line[6]) << " ";
      line.erase(0, 7);
    } else if (line[0] == 'R') {
      int amount = nm.GetVal(line[7]);
      line.erase(0, 17);
      //std::cout << "Repeating amount: " << amount << " \n";
      int a, b;
      GetCommandBounds(line, a, b);
      for (int i = 0; i < amount; i++) {
	
        ProcessLine(line.substr(a,b));
      }
      return;
    } else {
      std::cout << "unexpected char " << line[0] << "\n";
      return;
    }
    if (line.size() > 1)
      ProcessLine(line);
  }

  std::string GetCommand() {
    std::string cs = "";
    uint icount = 0;
    while (true) {
      char ch;
      std::cin.get(ch);
      if (ch == '\n') {
        if (icount == 0)
          break;
        else
          cs.push_back(
              ' '); // convert newline to space when we're inside a command
        continue;
      } else if (ch == '(')
        icount++;
      else if (ch == ')')
        icount--;

      cs.push_back(ch);
    }
    return cs;
  }
};

int main() {
  Interpreter in;
  // for (int i = 0; i < 7; i++) {
  std::string cli;
  while (true) {
    std::string s = in.GetCommand();
    //std::cout << "\n" << "Output of line \"" << s << "\": \n";
    if (s.empty())
      break;
    cli.append(s);
    cli.push_back(' ');
  }
  
  in.ProcessLine(cli);

  std::cout << "\n";
}

Test details

Test 1 (public)

Group: 1, 2, 3

Verdict: ACCEPTED

input
PRINT X
INCREASE X
PRINT X
INCREASE X
PRINT X
...

correct output
0 1 2 0 

user output
0 1 2 0 

Test 2 (public)

Group: 1, 2, 3

Verdict:

input
INCREASE
X
# aybabtu
   PRINT    X
INCREASE # test
...

correct output
1 3 

user output
(empty)

Feedback: Output is shorter than expected

Test 3 (public)

Group: 1, 2, 3

Verdict:

input
# Create number 3
INCREASE X
INCREASE X
INCREASE X

...

correct output

user output
(empty)

Feedback: Output is shorter than expected

Test 4 (public)

Group: 1, 2, 3

Verdict: ACCEPTED

input
INCREASE A
PRINT A
INCREASE B
PRINT B
INCREASE C
...

correct output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

Test 5 (public)

Group: 1, 2, 3

Verdict: ACCEPTED

input
INCREASE X
INCREASE X
INCREASE X
INCREASE X
INCREASE X
...

correct output
999 

user output
999 

Test 6 (public)

Group: 1, 2, 3

Verdict: ACCEPTED

input
PRINT X
PRINT X
PRINT X
PRINT X
PRINT X
...

correct output
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

user output
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

Test 7 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
5 5 5 5 5 

user output
(empty)

Feedback: Output is shorter than expected

Test 8 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
0 0 0 0 0 

user output
(empty)

Feedback: Output is shorter than expected

Test 9 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
6 7 8 9 10 

user output
(empty)

Feedback: Output is shorter than expected

Test 10 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
5 5 

user output
(empty)

Feedback: Output is shorter than expected

Test 11 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
20 

user output
(empty)

Feedback: Output is shorter than expected

Test 12 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A

INCREASE B
INCREASE B
...

correct output
42 

user output
(empty)

Feedback: Output is shorter than expected

Test 13 (public)

Group: 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 

user output
(empty)

Feedback: Output is shorter than expected

Test 14 (public)

Group: 3

Verdict:

input
# Create number 3
INCREASE A INCREASE A INCREASE...

correct output
12 

user output
(empty)

Feedback: Output is shorter than expected

Test 15 (public)

Group: 3

Verdict:

input
INCREASE X
INCREASE X
INCREASE X
INCREASE X
INCREASE X
...

correct output
531441 

user output
(empty)

Feedback: Output is shorter than expected

Test 16 (public)

Group: 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
1337 

user output
(empty)

Feedback: Output is shorter than expected

Test 17 (public)

Group: 3

Verdict:

input
INCREASE A
INCREASE A

REPEAT A TIMES (
    REPEAT A TIMES (
...

correct output
1 2 1 2 1 1 3 4 3 4 3 4 3 4 3 ...

user output
(empty)

Feedback: Output is shorter than expected

Test 18 (public)

Group: 3

Verdict:

input
# Efficient algorithm for find...

correct output
2 3 5 7 11 13 17 19 23 29 31 3...

user output
(empty)

Feedback: Output is shorter than expected