728x90

Coding Exercise 88

[백준 #2108] 통계학 - 파이썬(python)

문제만 보고 굉장히 쉽다고 생각했었는데, 내가 몰랐던 또 다른 라이브러리의 함수를 써서 풀었어야 했다.. def cnt_of(arr): cntlist=list(set(arr)) cnt=[] ver=[] for i in cntlist: cnt.append(arr.count(i)) a=max(cnt) while a==max(cnt): ver.append(cntlist[cnt.index(a)]) cnt[cnt.index(a)]=0 if len(ver)==1: return ver[0] else: return(ver[1]) N=int(input()) org=[] for i in range(N): org.append(int(input())) org.sort() print(int(round(sum(org)/N,0))..

Baekjoon Case 2021.08.11

[백준 #10989] 수 정렬하기3(카운팅 정렬) - 파이썬(python)

처음엔 똑같은 문제가 계속 나와서 왜 그런거지 생각하면서 전에 했던 것 대로 똑같이 했더니 계속 메모리 초과가 났다.. 아마 input,count,ouput array를 다 따로 만들어서 그런듯,, 카운팅 정렬을 이해하는데도 엄청나게 많은 시간이 걸렸는데, 그것을 나만의 코드로 짜려고 하니까 머리에 쥐 날 뻔 했다. import sys N = int(input()) check_list = [0] * 10001 for i in range(N): input_num = int(sys.stdin.readline()) check_list[input_num] = check_list[input_num] + 1 for i in range(10001): if check_list[i] != 0: for j in range..

Baekjoon Case 2021.08.11

[PANDAS] Series & DataFrame 생성하기

데이터 시각화의 중요한 PANDAS import pandas as pd new_sr=pd.Series([배열], name='배열이름', index=[인덱스배열]) 1 차원 Series 생성 name, index는 생략가능함. name 생략하는경우 : None index 생략하는 경우: 0,1,2, ... import pandas as pd new_df=pd.DataFrame([2차원 배열], index=[인덱스배열], columns=[컬럼의 배열] 2차원 DataFrame 생성 new_df.loc[:,'컬럼값']=[배열] DataFrame에 새로운 열 생성하기. 초기 생성시에는 2차원 배열이 index 기준으로 값이 입력되는데, 추가 할 때는 column 기준으로 입력되니 주의하자. 빈 값을 넣으려면, ..

Machine Learning 2021.08.10

[백준 #1436] 영화감독 숌 - 파이썬(python)

브루트 포스 단계인데 왜 이런 문제가 나왔지.. 라고 한참 생각했던 문제다. 되게 간단한건데 왜 자꾸 틀리지..하면서 좀 헤맸던 것 같음 def possum(n): pos=[] while n>0: pos.append(n%10) n=n//10 if n%10==n: pos.append(n) break if pos.count(6)>=3: return(True) N=int(input()) a=1 cnt=0 while True: if possum(a): cnt+=1 if cnt==N:break a+=1 print(a) 처음에는 문제를 6이 3개 들어가는 수를 구하라는 건 줄 알고, 이전에 자릿수 더하는 분해합 문제에서 썼었던 함수를 조금 변형해서 코드를 짰다. 계속 틀리다고 해서 대체 뭐가 문제야.. 했는데 알고..

Baekjoon Case 2021.08.10
728x90