목록Coding Problems (4)
Jun Hyuk Kim's Blog
So this happened when I tried to solve a programming problem using python's round function. Some errors from test cases were found and I was trying to find out why those errors were happening. round(0.5) = 0 ??? round(1.5) = 2 round(2.5) = 2 ??? The rounding that we learn usually is where the number is rounded up if the number after the decimal is 5 or larger. So why are the results above happen..
Most coding problems use sys.stdin because it is very fast compared to the input function, but there are some changes that people make. 1. sys.stdin.readline() takes the '\n' into the string. An addicitonal .rstrip() removes the '\n' character and any extra whitespaces in the end and front. If you want to keep the whitespaces at the end or the front, just pass an argument(.rstrip('\n')). 2. For ..
I can get my desired result by spliting the process to small parts. Just know that the problem I got is to check how many sub-strings contains exactly Ex: 'IOIOI' So when I tried to make the whole code at once I got errors constantly. So I tried changing the question into parts and coding them without worrying about the time complexity. import sys P_num = int(sys.stdin.readline().rstrip()) str_l..
Learned that when using python [[0] * width] * height Is wrong and [[0 for _ in range(width)] for __ in range(height)] Is correct to make 2d arrays As you can see when the first_arr[1][2] is set to '1' all the other rows are affected too. I think this is because when first_arr = [[0] * width] * height is inputed, first a row with 'width' number of '0' is made. Then the same list is made as an in..