CSES - Datatähti 2024 alku - Results
Submission details
Task:Monistus
Sender:andreibe
Submission time:2023-10-30 18:03:05 +0200
Language:Java
Status:COMPILE ERROR

Compiler report

input/b.java:50: error: reached end of file while parsing
    }
     ^
1 error

Code

import java.util.Scanner;
 
public class Datatahti {
    private static class Node {
        public Node(Node next, char c) {
            this.next = next;
            this.c = c;
        }
 
        private Node next;
        private char c;
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        char[] s = scanner.nextLine().toCharArray();
        Node last = new Node(null, s[0]);
        Node start = last;
        for (int i = 1; i < s.length; i++) {
            Node node = new Node(null, s[i]);
            last.next = node;
            last = node;
        }
        StringBuilder builder = new StringBuilder();
        while (start.next != null) {
            char c = start.c;
            if (Character.isDigit(c)) {
                int i = c - '0';
 
                Node next = start.next;
 
 
                char[] nextIElements = new char[i];
                for (int j = 0; j < i; j++) {
                    nextIElements[j] = next.c;
                    if (j != i -1) next = next.next;
                }
                Node nextOrg = next.next;
                for (char cc : nextIElements) {
                    Node node = new Node(null, cc);
                    next.next = node;
                    next = node;
                }
                next.next = nextOrg;
            } else {
                builder.append(c);
            }
            start = start.next;
        }
        System.out.println(builder.append(start.c));
    }