Help me to find this problem's rule,I seem to haven't got any ideas for this problem in Python!

+1 vote
asked Oct 20, 2018 by Tether

Chef is practising his typing skills since his current typing speed is very low. He uses a training application that displays some words one by one for Chef to type.

When typing a word, Chef takes 0.2 seconds to type the first character; for each other character of this word, he takes 0.2 seconds to type this character if it is written with a different hand than the previous character, or 0.4 seconds if it is written with the same hand. The time taken to type a word is the sum of times taken to type all of its characters. However, if a word has already appeared during practice, Chef can type it in half the time it took him to type this word for the first time.

Currently, Chef is practising in easy mode, which only uses words that consists of characters 'd', 'f', 'j' and 'k'. The characters 'd' and 'f' are written using the left hand, while the characters 'j' and 'k' are written using the right hand.

Given the words that appeared during Chef's practice, calculate the total time taken by Chef to type all the words.

Input

  • The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
  • The first line of each test case contains a single integer NN denoting the number of words Chef had to type.
  • Each of the following NN lines contains a single string — a word Chef has to type.

Output

For each test case, print a single line containing one integer — the time taken by Chef to type all the words, in the units of tenths of seconds.

Constraints

  • 1T1001≤T≤100
  • 1N1001≤N≤100
  • each word contains only characters 'd', 'f', 'j', 'k'
  • the length of each word does not exceed 2020

Subtasks

Subtask #1 (100 points): original constraints

Example Input

1
5
fdjkd
dfjdk
dfd
fdjkd
kkjjk

Example Output

61

1 Answer

0 votes
answered May 21, 2019 by Lubo
If I understand your task, the solution is very short. But I can't read from file, so in my solution file content is in list:

zoz = {'ff':4,'fd':4,'fj':2,'fk':2,
        'df':4,'dd':4,'dj':2,'dk':2,
        'jf':2,'jd':2,'jj':4,'jk':4,
        'kf':2,'kd':2,'kj':4,'kk':4}
vstup = ['1','5','fdjkd','dfjdk','dfd','fdjkd','kkjjk']
hotovo = []
poc_t = int(vstup.pop(0))
for i in range(poc_t):
    poc_s=int(vstup.pop(0))
    cas = 0
    for s in range(poc_s):
        slovo = vstup.pop(0)
        scas = 2
        for p in range(len(slovo)-1):
            scas += zoz[slovo[p:p+2]]
        if slovo in hotovo:
            scas = scas / 2
        cas += scas
        hotovo.append(slovo)
    print(cas)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...