Keiss USACO

 avatar
unknown
plain_text
3 years ago
1.9 kB
4
Indexable
#Started: 10:53
#Finished 1:54 AM (Gave up)
#Program only works for one operator :(


list = []
wordlist = []
#two lists: list is for compiling the characters and wordlist is the end product

z = input("input")
def split(word):
    return [char for char in word]
char = split(z)
#split the formula into separate characters

def output():
    word = ''.join(list)
    wordlist.append(word)
#turns the characters back into words

#check and see if there are any special characters and return None if there arent
done = False
r = 0
#variable r (changes what is inputted)
o = 6
#limiting variable
#HOW DO I MAKE IT NOT DEPENDENT ON ONE VARIABLE????
while o >= r:
        for n in range(len(char)):
        #Run through from 0 to whatever
            if char[n] == '?':
                if r == 6:
                    list.remove(char[n-1])
                    #get rid of the preceding char
                r += 6
                #Add 6 to make sure that it only runs twice
                done = True
            elif char[n] == '*':
                if r == 0:
                    list.remove(char[n-1])
                else:
                    list.remove(char[n - 1])
                    list.extend(char[n-1]*round(r/2))
                    #extend multiplies the char (i would not use this if there was a better way)
                r += 2
                done = True

            elif char[n] == "+":
                list.extend(char[n - 1] * round(r / 3))
                r += 3
                done = True
            else:
                list.append(char[n])
                #if not a special character, just append to list

        if done == False:
            print(None)
            r+=2
            #If none, kill loop and print None
        else:
            output()
            #pull output and append to word. Clear the list afterward
            list.clear()
print(wordlist)
#print final product
Editor is loading...