11654번 아스키 코드
inputletter = input()
print(ord(inputletter))
11720번 숫자의 합
length = int(input())
numbers = input()
ans = 0
for i in range (length):
ans += int(numbers[i])
print(ans)
10809 알파벳 찾기
S = input()
alphabet = {'a': -1, 'b': -1, 'c': -1, 'd': -1, 'e': -1, 'f': -1, 'g': -1, 'h': -1, 'i': -1, 'j': -1, 'k': -1, 'l': -1, 'm': -1, 'n': -1, 'o': -1, 'p': -1, 'q': -1, 'r': -1, 'x': -1, 't': -1, 'u': -1, 'v': -1, 'w': -1, 'x': -1, 'y': -1, 'z': -1}
i = 0
while i < len(S):
index = S[i]
if alphabet[index] == -1:
alphabet[index] = i
i += 1
returns = ''
for val in alphabet.values():
returns += ' ' + str(val)
print(returns)
런타임 에러 떴다........ 다시....해야지.....
해싱 수업 들은 후 딕셔너리로 해야지!! 하면서 딕셔너리 만들었는데.
그게 문제가 아니다...ㅠ
모든걸 딕셔너리로 해결할 필요는 없다.
S = input()
alphabets = 'abcdefghijklmnopqrstuvwxyz'
for alphabet in alphabets:
print(S.find(alphabet), end = ' ')
# 2675 문자열 반복
caseNo = int(input())
for i in range (caseNo):
repeat, testcase = input().split()
for case in testcase:
print(case * int(repeat), end = '')
print('')
1157 단어공부
#알파벳이 나온 숫자를 딕셔너리에 입력 후, key가 max 인 알파벳을 출력한다
#만약 알파벳이 1개보다 길면, 물음표 출력.
word = input()
#1. input을 받은 후 대문자로 변경
word_capital = ''
for a in word:
if ord(a) > 96:
a = chr(ord(a)-32)
word_capital += a
#2. count number of each alphabet
a_set = set()
a_dict = {}
for a in word_capital:
if a not in a_set:
a_set.add(a)
#3. make a dictionary...
for a in a_set:
a_count = word_capital.count(a)
if a_count in a_dict:
a_dict[a_count] = a_dict[a_count] + a
else:
a_dict[a_count] = a
if len(a_dict[max(a_dict)]) > 1:
print('?')
else:
print(a_dict[max(a_dict)])
처음에 이렇게 했는데.. 코드가 너무 길다 ('맞혔습니다!' 가 나오긴 했음..)
아래처럼 코드 길이를 줄일 수 있다.
for 문 두개를 input().upper()
그리고 set(word)로 해결....
word = input().upper()
a_set = set(word)
a_dict = {}
#3. make a dictionary...
for a in a_set:
a_count = word.count(a)
if a_count in a_dict:
a_dict[a_count] = a_dict[a_count] + a
else:
a_dict[a_count] = a
if len(a_dict[max(a_dict)]) > 1:
print('?')
else:
print(a_dict[max(a_dict)])
1152 단어의 개수
words = input()
words_set = words.split()
print(len(words_set))
# 2908 상수 (사람 이름이었어....)
a, b = input().split()
sangsu_a = ''
sangsu_b = ''
for num in a:
sangsu_a = num + sangsu_a
for num in b:
sangsu_b = num + sangsu_b
print(max([int(sangsu_a), int(sangsu_b)]))
#5622 다이얼
무식한 방식으로 아래처럼 풀어봤따....
dialnumber = input()
time = 0
for a in dialnumber:
if a in 'ABC':
time += 3
elif a in 'DEF':
time += 4
elif a in 'GHI':
time += 5
elif a in 'JKL':
time += 6
elif a in 'MNO':
time += 7
elif a in 'PQRS':
time += 8
elif a in 'TUV':
time += 9
else:
time += 10
print(time)
자 이제 똑똑한 방법을 고민해봐야겠다....
#2941 크로아티아 알파벳
알파벳 set 을 만든 후 그 안에 있으면 카운트...하기...
croatia = input()
alphabet = {'c=', 'c-', 'dz=', 'd-', 'lj', 'nj', 's=', 'z='}
cAlphabet = 0
i = 0
while i < len(croatia):
if croatia[i:i+2] in alphabet:
i += 2
elif croatia[i:i+3] in alphabet:
i += 3
else:
i += 1
cAlphabet += 1
print(cAlphabet)
#1316 그룹단어체커
wordN = int(input())
count = 0
def ifgroupword(s):
i = 0
alphabet = set()
s += ' '
while i < len(s)-1 :
if s[i] == s[i+1]:
i += 1
else:
if s[i] in alphabet:
return 0
break
else:
alphabet.add(s[i])
i += 1
return 1
for i in range (wordN):
inputword = input()
count += ifgroupword(inputword)
print(count)
코드 길이 줄이고 싶은데 일단 푸는데에 의의를....ㅠ
'Python' 카테고리의 다른 글
3.2. Maps (0) | 2022.03.13 |
---|---|
3.1. Set (0) | 2022.03.13 |
Searching problem (linear, binary) (0) | 2022.03.10 |
[백준 단계별로 풀어보기] python3 함수 (0) | 2021.12.29 |
[백준 단계별로 풀어보기] python3 1차원 배열 (0) | 2021.12.27 |