1. 문자열 집합 ( 백준 14425번 )
14425번: 문자열 집합
첫째 줄에 문자열의 개수 N과 M (1 ≤ N ≤ 10,000, 1 ≤ M ≤ 10,000)이 주어진다. 다음 N개의 줄에는 집합 S에 포함되어 있는 문자열들이 주어진다. 다음 M개의 줄에는 검사해야 하는 문자열들이 주어
www.acmicpc.net
직접 작성한 코드)
n,m=map(int,input().split())
array=[]
array2=[]
count=0
for i in range(n):
nn=input()
array.append(nn)
for i in range(m):
mm=input()
if mm not in array:
continue
else:
count+=1
print(count)
2. 그룹 단어 체커 (백준 1316번)
1316번: 그룹 단어 체커
그룹 단어란 단어에 존재하는 모든 문자에 대해서, 각 문자가 연속해서 나타나는 경우만을 말한다. 예를 들면, ccazzzzbb는 c, a, z, b가 모두 연속해서 나타나고, kin도 k, i, n이 연속해서 나타나기 때
www.acmicpc.net
직접 작성한 코드)
n=int(input())
count=0
for i in range(n):
value=True
array=[]
string=input()
array.append(string[0])
for j in range(1,len(string)):
if string[j]!=string[j-1]:
if string[j] in array:
count-=1
break
array.append(string[j])
count+=1
print(count)
➡️ for문이 만약 for j in range(0,4):
이면 j는 0,1,2,3 이 동작된다.
➡️ 만약 이중 for문을 break 해야할 때는 변수를 하나 더 사용하자!
'CS Study > algorithm' 카테고리의 다른 글
[Algorithm] 시간 복잡도 (0) | 2023.03.05 |
---|---|
시뮬레이션 문제 풀이 (0) | 2022.09.16 |
다이나믹 프로그래밍 문제 풀이 (0) | 2022.07.31 |
이진 탐색 문제풀이 (0) | 2022.07.30 |
기타 문제풀이 (0) | 2022.07.22 |