Skip to content

Split the Str Ing

Testcase generation code for Split the Str Ing task on CodeChef.

generate.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import logging
import string

from testcase_maker.generator import TestcaseGenerator
from testcase_maker.values import ValueGroup, NamedValue, RandomInt, LoopValue, ValueRef, RandomChoice

logging.basicConfig(level=logging.INFO)

# Firstly, create a new container to make the testcase stdin structure.
values = ValueGroup()

# The first line of the input contains a single integer T denoting the number of test cases.
values.add(NamedValue(
    name="T",
    value=RandomInt(min=1, max=10 ** 4)
))
values.newline()

# For each testcase:
#  - The first line of each test case contains a single integer N.
#  - The second line contains a single string S.
testcase = ValueGroup()
testcase.add(NamedValue(
    name="N",
    value=RandomInt(min=2, max=10 ** 5)
))
testcase.newline()
testcase.add(LoopValue(
    value=RandomChoice(items=list(string.ascii_lowercase)),
    amount=ValueRef(name="N"),
    delimiter=""
))

# Then create T number of testcases.
values.add(LoopValue(
    value=testcase,
    amount=ValueRef(name="T"),
    delimiter="\n"
))

# Generate the testcases
generator = TestcaseGenerator(values=values, answer_script="./solution.py")
generator.generate()

solution.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
T = int(input())

for _ in range(T):
    n = int(input())
    word = input().rstrip()
    mapping = {}
    for letter in word:
        if letter in mapping:
            mapping[letter] += 1
        else:
            mapping[letter] = 1

    last = mapping.get(word[-1], 0)
    print("YES" if last > 1 else "NO")