Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

xcc1

백준 문제별풀이 7단계(파이썬) 본문

백준

백준 문제별풀이 7단계(파이썬)

xcc1 2021. 9. 4. 18:49
  • 11654번 정답 
print(ord("{}".format(input())))

아스키코드가 뭔지 몰랐는데 이김에 배우게 되었다. 

아래는 아스키코드의 파이썬 변환 방법에 대한 블로그!

 

https://lsjsj92.tistory.com/201

 

이수진의 블로그

안녕하세요. 이수진이라고 합니다. 이 블로그는 AI(인공지능), Data Science(데이터 사이언스), Machine Learning, Deep Learning 등의 IT를 주제로 운영하고 있는 블로그입니다.

lsjsj92.tistory.com

 

 

 

  • 11720번 정답
n = int(input())

nums = list(str(input()))
int_nums = []

for i in range(n):
    int_nums.append(int(nums[i]))

print(sum(int_nums))

 

 

 

  • 10809번 정답

find를 몰라서 ...

#문자를 받는다
s = list(map(str,input()))

#사전과 아스키 코드를 사용해서 
#{a : -1 , b : -1 ...} 이런 사전을 작성
dic = {}
for n in range(97,123):
    dic[chr(n)] = -1

#중복되는 알파벳은 '.'으로 대체하고
#자릿수를 부여해서 사전을 수정한다.
a = []
for i in range(len(s)):
    if s[i] in a:
        a.append(".")

    elif s[i] not in a:
        a.append(s[i])
        dic[s[i]] = i

#사전의 values만 추출...!!
for values in dic.values():
    print(values, end=" ")

 

find 함수를 사용하면!

 

s = input()
a = list(range(97, 123))


for x in a:
    print(s.find(chr(x)))
    # chr(97) = a 를 s(받은 문자열)에서 찾아라.
    # 있는 경우에는 그 문자가 처음등장한 위치를,
    # 없는 경우에는 -1를 반환!

 

 

 

 

  • 2675번 정답
T = int(input())

#2번 반복할거니까..!
for t in range(T):
    a = ""
    R , S = map(str, input().split())
    for s in S:
        a += int(R) * s
    print(a)

 

 

 

  • 1157번 정답 
#input으로 받은 문자를 모두 대문자화 한다.
word = input().upper()

#set으로 중복을 없애준다.
n_list = list(set(word))

#개수를 세어서 리스트를 만들어준다. 
w_list = []
for w in n_list:
    w_list.append(word.count(w))

#최대개수에서 공통이 있으면 ?을 출력
if w_list.count(max(w_list)) > 1:
	print("?")
#그렇지 않으면 그 최대개수에 해당되는 문자를 출력
else:
	most = w_list.index(max(w_list))
    print(n_list[most])

어려운 문제였다. 여러 번 검색하면서 최적을 찾다가 몇시간을 헤매고...

 

 

 

 

  • 1152번 정답
s = input().split()
print(len(s))

 

 

 

 

  • 2908번 정답
nums =input()
rm = nums[::-1]
int_nums = map(int,rm.split())
print(max(int_nums))

 

 

 

 

  • 5622번 정답
word = input()
n = []
for i in range(len(word)):
    code = ord(word[i])
    if 65 <= code <= 67:
        n.insert(i,3)
    elif 68 <= code <= 70:
        n.insert(i,4)
    elif code <= 73:
        n.insert(i,5)
    elif code <= 76:
        n.insert(i,6)
    elif code <= 79:
        n.insert(i,7)
    elif code <= 83:
        n.insert(i,8)
    elif code <= 86:
        n.insert(i,9)
    else:
        n.insert(i,10)

print(sum(n))

노가다로 했는데... 아마 다른 방법이 있을 것 같다. 

 

 

 

  • 2941번 정답
word = input()
cro = ['c=', 'c-', 'dz=', 'd-', 'lj', 'nj', 's=', 'z=']
for i in cro:
    word = word.replace(i,'a')
print(len(word))

 

 

 

  • 1316번 정답
N = int(input())
cnt = 0

for i in range(N):
    word = input()
    for n in range(len(word)):
        target = word[n]
        if len(word) <= 2:
            cnt +=1
        elif word.find(target, n+2) != -1:
            break

print(cnt)

이게 왜 안될까아...ㅠㅠ

해답보고 똑바로 적어도 틀렸다고 나온다..... 이걸 어찌할까.....ㅠㅠ

 

N = int(input())
cnt = 0

for i in range(N):
    word = input()
    for n in range(len(word)-1):
        if word[n] != word[n+1]:
            if word[n] in word[n+1:]:
                N -= 1
            

print(N)

 

 

문자열.... 오래걸렸다.. 

빨리 열심히 해서 코테도 합격하고 싶은 마음!

아자아자 화이팅

'백준' 카테고리의 다른 글

백준 10250:ACM 호텔  (0) 2021.10.28
백준 1193번  (0) 2021.10.27
백준 단계별 풀이 6단계 (파이썬)  (0) 2021.09.02
백준 단계별 풀이 5단계 (파이썬)  (0) 2021.08.31
백준 단계별 풀이 4단계 (파이썬)  (0) 2021.08.27