top of page

CCC 1998 S4:Lottery

  1. Change the input string as a list

2. Handle "X" first, if find an "X", combine its previous number a and its next number b as "(a X b)".

3. Handle "+" and "-", Add each odd place as "n)", and count ")" as c.

4. Add c "(" at the first number "a" as "((((..a"

5. Output result as [:-1]

n = int(input())

for i in range(n):
    ss = input().split()
    while "X" in ss:
        pos = ss.index("X")
        state = "(" + " ".join(ss[pos-1:pos+2]) + ")"
        del ss[pos]
        del ss[pos]
        del ss[pos-1]
        ss = ss[:pos-1] + [state] + ss[pos-1:]
    sslen = len(ss)//2+1
    for j in range(1, sslen):
        ss[2*j] += ")"
    ss[0] = "("*(len(ss)//2-1) + ss[0]
    if len(ss)//2-1 < 0:
        ss[0] = ss[0][1-len(ss)//2:]
    ans = " ".join(ss)

Recent Posts

See All

CCC '24 J5 - Harvest Waterloo

#include<iostream> #include <vector> #include <algorithm> #include <cmath> #include <stack> using namespace std; int main() { int r, c, sr, sc; cin >> r; cin >> c; int p[r][c]; bool v

CCC '24 J4 - Troublesome Keys

#include <iostream> #include <string> #include <map> #include <vector> #include <algorithm> #include <cmath> using namespace std; int main() { string ps; string ds; cin >> ps; cin >> ds;

CCC '22 J5 - Square Pool

#include<iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; bool rowcom(pair<int, int> a, pair<int, int> b){ return a.first < b.first; } bool colcom(pair<int,


bottom of page