Python – Algorithm Challenge – First Day At School

Yesterday, I have started to solve problems from a challenging Russian site for programming competitions. Today, I have decided to spend about 30 minutes on another problem, which seemed easy, but I am already spending hours on it, without being able to solve it for full points.

Python

The point is, that currently I am not even able to locate what should be improved in my code, as far as any input returns the desired output. Indeed, the code is a little messy, because I have not updated it. Here is the task:


2046. The First Day at School
Time limit: 1.0 second
Memory limit: 64 MB
Vasya is a young and very promising android. Today is his first day at University. Vasya has very carefully studied the list of all courses on the wall near the Dean’s office and has chosen the ones to attend. Now he wants to write down his own week timetable. Help him do this.
Input
The first line contains an integer n that is the number of courses Vasya is going to attend (1 ≤ n ≤ 12). After that the courses are listed, each is described in two lines.
The first line of a course description contains its name. The name of the course may consist of up to five words, which are divided by exactly one space (there are no spaces before the first word and after the last one). The words consist of capital and lowercase Latin letters. The length of every word is within the range from 1 to 10.
The second line of a course description contains the day of week and the number of a lesson, when it takes place. The day of week may take one of the three values: “Tuesday”, “Thursday” и “Saturday”. The number of a lesson is an integer from 1 to 4. There are no two courses, Vasya has chosen, taking place at the same time.
Output
Output the timetable as a table of the size 4×3. The columns of the table should correspond to the three academic days: the first column — to Tuesday, the second — to Thursday, the third — to Saturday. The rows should correspond to the four classes. The width of each column should be equal to 10 characters. The height of the row of the table equals to the height of the highest of its cells. If all the cells in the row are empty then the height of the row should be equal 1 character. If some word doesn’t find room in the current line, it should be placed in the next line. The text in the cell should be aligned to top and left borders. Make the table itself using characters “-” (ASCII 45), “+” (ASCII 43) and “|” (ASCII 124).


As far as I have tried to update the whole thing quite a lot of times, at the end I managed to make it working the way I wanted. But it still passes only the first 2 tests, stopping on the 3. one. Quite fun. This is the output from some extreme tests (above the required input for words) from my code:

wingIDE

As you see in the example from Tuesday 4 =>”d LALALAL LALALAL LLA LAL LAL L L L“, I have even tried with more than 5 words and it unites them into one cell pretty neatly. So, anyone with ideas where is my program failing?

In general, the task was intersting and I am quite happy that I spent some hours on it.

Here comes the code, try to improve it and let me know if you have managed to take full points from it! 🙂

Thank you for your interst!

Edit 1:

I have fixed the function def listSplitMe(strText):, but it still does not let me pass 🙂

Tagged with: , ,