CSES - Datatähti 2018 alku - Results
Submission details
Task:Merkkijono
Sender:Oskar
Submission time:2017-10-04 19:37:50 +0300
Language:Java
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.21 sdetails
#2ACCEPTED0.32 sdetails
#3ACCEPTED0.37 sdetails
#4ACCEPTED0.24 sdetails
#5ACCEPTED0.33 sdetails
#6ACCEPTED0.21 sdetails
#7ACCEPTED0.21 sdetails
#8ACCEPTED0.23 sdetails
#9ACCEPTED0.23 sdetails
#10ACCEPTED0.23 sdetails

Code

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String currentString = s.nextLine();
        while (true) {
            List<String> list = getAsList(currentString);
            if (containsLongerThan(list, 2)) {
                currentString = getAsStringAndRemove(list);
            } else {
                System.out.println(currentString);
                break;
            }
        }
    }

    public static String getAsStringAndRemove(List<String> list) {
        List<String> newList = list;
        for (String s : list) {
            if (!(s.length() < 2)) {
                newList.remove(s);
                break;
            }
        }

        StringBuilder sb = new StringBuilder();
        for (String s : newList) {
            sb.append(s);
        }

        return sb.toString();
    }


    public static ArrayList<String> getAsList(String input) {
        //TODO: change last array
        char last = '.';
        StringBuilder sb = new StringBuilder();
        ArrayList<String> list = new ArrayList<>();
        final int len = input.length();
        for (int i = 0; i < len; i++) {
            char c = input.charAt(i);
            if (i == 0) {
                last = c;
                sb.append(c);
            } else if (i == len - 1) {
                if (last == c) {
                    sb.append(c);
                    list.add(sb.toString());
                } else {
                    list.add(sb.toString());
                    sb = new StringBuilder();
                    sb.append(c);
                    list.add(sb.toString());
                }
            } else {
                if (last == c) {
                    sb.append(c);
                } else {
                    list.add(sb.toString());
                    sb = new StringBuilder();
                    sb.append(c);
                    last = c;
                }
            }
        }
        return list;
    }

    public static boolean containsLongerThan(List<String> list, int limit) {
        for (String s : list) {
            if (!(s.length() < limit)) {
                return true;
            }
        }
        return false;
    }
}

Test details

Test 1

Verdict: ACCEPTED

input
ABABABABABABABABABABABABABABAB...

correct output
ABABABABABABABABABABABABABABAB...

user output
ABABABABABABABABABABABABABABAB...

Test 2

Verdict: ACCEPTED

input
AABBAABBAABBAABBAABBAABBAABBAA...

correct output
(empty)

user output
(empty)

Test 3

Verdict: ACCEPTED

input
ABABABABABABABABABABABABABABAB...

correct output
(empty)

user output
(empty)

Test 4

Verdict: ACCEPTED

input
BBABABBBBBAABBBABABABBBBAAABAB...

correct output
BAB

user output
BAB

Test 5

Verdict: ACCEPTED

input
ACDCBBACDBBBACAACBBDBADBAABABA...

correct output
ACDCACDADBADABACACDCADADABABCA...

user output
ACDCACDADBADABACACDCADADABABCA...

Test 6

Verdict: ACCEPTED

input
EETFHIJOGACDHMGVFJCMETMZDEITTR...

correct output
TFHIJOGACDHMGVFJCMETMZDEIROTET...

user output
TFHIJOGACDHMGVFJCMETMZDEIROTET...

Test 7

Verdict: ACCEPTED

input
GOONLAHLYPRFCZKIKSJWAWWYJJPCDB...

correct output
GNLAHLYPRFCZKIKSJWAYPCDNWYMRCE...

user output
GNLAHLYPRFCZKIKSJWAYPCDNWYMRCE...

Test 8

Verdict: ACCEPTED

input
PISHWMOTCDDZFRMYMOMYDYYGJZIQHS...

correct output
PISHWMOTCZFRMYMOMYDGJZIQHSVAOK...

user output
PISHWMOTCZFRMYMOMYDGJZIQHSVAOK...

Test 9

Verdict: ACCEPTED

input
QUVVTPXAMWWODFXRONJODPGBTCISGM...

correct output
QUTPXAMODFXRONJODPGBTCISGMVRBW...

user output
QUTPXAMODFXRONJODPGBTCISGMVRBW...

Test 10

Verdict: ACCEPTED

input
POXHAHYEZTLYNFSLABODMRNKDSKROZ...

correct output
POXHAHYEZTLYNFSLABODMRNKDSKROZ...

user output
POXHAHYEZTLYNFSLABODMRNKDSKROZ...