본문 바로가기
백준 알고리즘

파이썬) 백준 알고리즘 | 9494번 : Text Roll

by 코딩새내기_ 2022. 1. 30.

https://www.acmicpc.net/problem/9494

 

9494번: Text Roll

There will be several test cases in the input. Each test case will begin with an integer n (1≤n≤1,000) on its own line, indicating the number of lines of text. On each of the next n lines will be text, consisting of printable ASCII characters and space

www.acmicpc.net

문제

Take some text. Put a small ball at the top of the first letter of the first word of the first sentence. The ball is drawn via gravity downwards. The text is also at a slight angle, so the ball wants to also move towards the right. The ball can freely move between the lines, and can drop through spaces. Considering the first column to be column 1, what column will the ball end up in? In this example, the ball ends up in column 8. 

입력

There will be several test cases in the input. Each test case will begin with an integer n (1≤n≤1,000) on its own line, indicating the number of lines of text. On each of the next n lines will be text, consisting of printable ASCII characters and spaces. There will be no tabs, nor any other unprintable characters. Each line will be between 1 and 100 characters long. The input will end with a line containing a single 0. 

출력

For each test case, output a single integer on its own line, indicating the column from which the ball will drop. Output no spaces, and do not separate answers with blank lines. 

qorwns 9494 'Text Roll' 문제입니다.

import sys

while True:
    sentence = []
    N = int(sys.stdin.readline())
    if N == 0:
        break
    for i in range(N):
        a = sys.stdin.readline().strip().split(" ")
        sentence.append(a)
    count = 1
    for i in range(N):
        for j in range(len(sentence[i])):
            if count <= sum(map(len,sentence[i][:j+1]))+j+1:
                count = sum(map(len,sentence[i][:j+1]))+j+1
                break
    print(count)

댓글