File tree 9 files changed +278
-0
lines changed
9 files changed +278
-0
lines changed Original file line number Diff line number Diff line change
1
+ import sys
2
+ input = sys .stdin .readline
3
+
4
+ def count_substring (string , n ):
5
+ # 주의! substring = {} 이와 같이 정의를 하면, set이 아닌 dictionary로 정의됩니다.
6
+ substring = set ()
7
+ # i 길이의 부분문자열을
8
+ for i in range (1 , n + 1 ):
9
+ # j 인덱스부터 시작해서 / i를 빼주지 않으면, string[i:i+j]에서 인덱스 에러가 납니다.
10
+ for j in range (n - i + 1 ):
11
+ substring .add (string [j :j + i ])
12
+
13
+ return len (substring )
14
+
15
+ # .rstrip()을 통해 '\n' 제거
16
+ s = input ().rstrip ()
17
+
18
+ print (count_substring (s , len (s )))
Original file line number Diff line number Diff line change
1
+ import sys
2
+ # 로컬에서 코드를 확인하기 위해, 파일로 입력을 전달합니다.
3
+ # sys.stdin = open('input.txt 파일경로', 'r') # 이 부분은 백준에 올릴 때는 주석처리합니다.
4
+ input = sys .stdin .readline
5
+
6
+
7
+ s , e , q = input ().split ()
8
+ attendance = set ()
9
+ answer = 0 # 출석 확인된 회원 수
10
+
11
+ # 이 문제는 파일의 끝 (EOF, End Of File)까지 입력을 받아야 하는 문제 입니다.
12
+ # try, except 문을 통해 입력이 들어오지 않는 경우에 대한 예외 처리를 해줍니다.
13
+ while (True ):
14
+ try :
15
+ time , name = input ().rstrip ().split ()
16
+ # 입장 확인
17
+ if time <= s :
18
+ attendance .add (name )
19
+ # 퇴장 확인
20
+ elif e <= time <= q :
21
+ if name in attendance :
22
+ answer += 1
23
+ attendance .remove (name ) # 중복 체크를 방지하기 위해 이름을 제거한다.
24
+
25
+ except :
26
+ # 입력이 끝났으므로, 출석 인원 출력
27
+ print (answer )
28
+ break
Original file line number Diff line number Diff line change
1
+ import sys
2
+ input = sys .stdin .readline
3
+
4
+ # key(확장자) - value(파일 개수) 쌍이 필요하므로 dict() 사용
5
+
6
+ n = int (input ())
7
+ extension = dict ()
8
+
9
+ for _ in range (n ):
10
+ # 입력을 '.'을 기준으로 나누어 리스트에 담고 (.split('.')), 두번째 요소(확장자)를 ext에 저장
11
+ ext = input ().rstrip ().split ('.' )[1 ]
12
+ # key 에러가 나지 않도록 ext가 딕셔너리에 있는지 확인
13
+ if ext in extension :
14
+ extension [ext ] += 1
15
+ else :
16
+ extension [ext ] = 1
17
+
18
+ answer = sorted (extension .items ())
19
+
20
+ for key , value in answer :
21
+ print (key , value )
Original file line number Diff line number Diff line change
1
+ import sys
2
+ input = sys .stdin .readline
3
+
4
+ n , m = map (int , input ().split ())
5
+
6
+ note = dict ()
7
+
8
+ for _ in range (n ):
9
+ word = input ().rstrip ()
10
+ # 길이가 m 미만이면 단어장에 들어가지 않음
11
+ if len (word ) < m :
12
+ continue
13
+
14
+ # key 에러를 방지하기 위해 딕셔너리에 단어가 있는지 확인
15
+ if word in note :
16
+ note [word ] += 1
17
+ else :
18
+ note [word ] = 1
19
+
20
+ # .keys() 딕셔너리의 key들을 iterator로 돌려주는 메소드
21
+ # 정렬을 위해 리스트에 담아줍니다.
22
+ arr = list (note .keys ())
23
+
24
+ # [영단어 우선 순위]
25
+ # 1. 자주 나오는 단어일 수록 (딕셔너리의 value 값) - 내림차순
26
+ # 2. 해당 단어의 길이가 길수록 - 내림차순
27
+ # 3. 알파벳 사전 순으로 - 오름차순
28
+ arr .sort (key = lambda x :(- note [x ], - len (x ), x ))
29
+
30
+ # 출력
31
+ for w in arr :
32
+ print (w )
Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by JIYOUNG.P on 2022-03-07.
3
+ //
4
+
5
+ #include < iostream>
6
+ #include < unordered_set>
7
+
8
+ using namespace std ;
9
+
10
+ /*
11
+ * ver1. set을 이요한 풀이입니다.
12
+ * 정렬을 할 필요가 없이, 삽입과 검색만 일어나는 문제입니다.
13
+ * 입력의 수가 최대 1,000,000으로 삽입과 탐색이 많이 일어납니다.
14
+ * 따라서, O(log N)의 set이 아니라 O(1)인 unordered_set을 사용해서 풀어야 합니다.
15
+ * */
16
+
17
+ int main () {
18
+ // 입출력 처리 속도 향상을 위한 코드
19
+ ios_base::sync_with_stdio (false );
20
+ cin.tie (NULL );
21
+ cout.tie (NULL );
22
+
23
+ // 입력
24
+ int t;
25
+ cin >> t;
26
+ while (t--) {
27
+ int n, m, input;
28
+ unordered_set<int > note1;
29
+
30
+ // 수첩1에 해당되는 원소들을 unordered_set에 삽입
31
+ cin >> n;
32
+ while (n--) {
33
+ cin >> input;
34
+ note1.insert (input);
35
+ }
36
+ cin >> m;
37
+ while (m--) {
38
+ cin >> input;
39
+ // 반복자를 이용해서 원소가 셋에 포함되어 있는지 확인
40
+ auto iter = note1.find (input);
41
+ if (iter == note1.end ()) {
42
+ cout << " 0\n " ;
43
+ } else {
44
+ cout << " 1\n " ;
45
+ }
46
+ }
47
+ }
48
+ return 0 ;
49
+ }
Original file line number Diff line number Diff line change
1
+ import sys
2
+ input = sys .stdin .readline
3
+
4
+ # ver1) 셋을 이용한 풀이입니다.
5
+
6
+
7
+ t = int (input ())
8
+
9
+ for _ in range (t ):
10
+ # 입력
11
+ n = int (input ())
12
+ note1 = set (map (int , input ().split ()))
13
+ m = int (input ())
14
+ note2 = list (map (int , input ().split ()))
15
+
16
+ # note2에 있는 숫자를 하나씩 꺼내 note1에 있는지 비교합니다.
17
+ for num in note2 :
18
+ if num in note1 :
19
+ print (1 )
20
+ else :
21
+ print (0 )
Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by JIYOUNG.P on 2022-03-08.
3
+ //
4
+
5
+ #include < iostream>
6
+ #include < vector>
7
+ #include < algorithm>
8
+
9
+ using namespace std ;
10
+
11
+ /*
12
+ * ver2. 아직 배우지는 않았지만, 후반부에 배울 이분탐색을 이용한 풀이입니다.
13
+ * O(n)의 시간복잡도를 갖는 선형탐색(linear search)는 달리, 이분탐색(binary search)는 O(logn)의 시간 복잡도를 갖습니다.
14
+ * */
15
+
16
+ int main () {
17
+ // 입출력 처리 속도 향상을 위한 코드
18
+ ios_base::sync_with_stdio (false );
19
+ cin.tie (NULL );
20
+ cout.tie (NULL );
21
+
22
+ // 입력
23
+ int t;
24
+ cin >> t;
25
+ while (t--) {
26
+ int n, m, input;
27
+
28
+ // 수첩1에 해당되는 원소들을 vector에 저장
29
+ cin >> n;
30
+ vector<int > note1 (n, 0 );
31
+ for (int i = 0 ; i < n; i++) {
32
+ cin >> note1[i];
33
+ }
34
+
35
+ // 이분탐색을 하기 위해 정렬
36
+ sort (note1.begin (), note1.end ());
37
+
38
+ cin >> m;
39
+ while (m--) {
40
+ cin >> input;
41
+ // 이분탐색 라이브러리 함수를 활용해, 원소가 수첩1에 있는지 확인
42
+ // binary_search() -> 이분탐색으로 원소가 있는지를 확인하고, 결과를 리턴하는 함수
43
+ if (binary_search (note1.begin (), note1.end (), input)) {
44
+ cout << " 1\n " ;
45
+ } else {
46
+ cout << " 0\n " ;
47
+ }
48
+ }
49
+ }
50
+ return 0 ;
51
+ }
Original file line number Diff line number Diff line change
1
+ import sys
2
+ from bisect import bisect_left , bisect_right
3
+ input = sys .stdin .readline
4
+
5
+ # ver2) 아직 배우지는 않았지만, 후반부에 배울 이분탐색을 이용한 풀이입니다.
6
+ # O(n)의 시간복잡도를 갖는 선형탐색(linear search)는 달리, 이분탐색(binary search)는 O(logn)의 시간 복잡도를 갖습니다.
7
+
8
+ t = int (input ())
9
+
10
+ for _ in range (t ):
11
+ # 입력
12
+ n = int (input ())
13
+ note1 = list (map (int , input ().split ()))
14
+ m = int (input ())
15
+ note2 = list (map (int , input ().split ()))
16
+
17
+ note1 .sort () # 이분탐색을 하기 위해서 정렬
18
+
19
+ # note2에 있는 숫자를 하나씩 꺼내 note1에 있는지 확인합니다.
20
+ for num in note2 :
21
+ # bisect_left 함수는 정렬된 리스트에서 새로운 값이 들어갈 수 있는 첫번째 인덱스를 리턴합니다.
22
+ # bisect_right 함수는 정렬된 리스트에서 새로운 값이 들어갈 수 있는 마지막 인덱스를 리턴합니다.
23
+ # 만약 num이 note1에 포함되어 있지 않다면, 둘의 결과 값은 같게 됩니다.
24
+ if bisect_left (note1 , num ) == bisect_right (note1 , num ):
25
+ print (0 )
26
+ else :
27
+ print (1 )
Original file line number Diff line number Diff line change
1
+ import sys
2
+ input = sys .stdin .readline
3
+
4
+ # 같은 종류의 옷이 각각 몇 벌 있는지만 알면 되는 문제
5
+
6
+ t = int (input ())
7
+
8
+ for _ in range (t ):
9
+ n = int (input ())
10
+ # 종류별 수를 저장할 딕셔너리
11
+ closet = dict ()
12
+
13
+ for _ in range (n ):
14
+ # 옷의 종류만 필요하므로 두번째 단어만 저장
15
+ type_of_cloth = input ().rstrip ().split ()[1 ]
16
+ # key 에러 방지를 위해 딕셔너리에 존재하는지 확인
17
+ if type_of_cloth in closet :
18
+ closet [type_of_cloth ] += 1
19
+ else :
20
+ closet [type_of_cloth ] = 1
21
+
22
+ answer = 1
23
+
24
+ # .values() : 딕셔너리에서 value들을 뽑아 iterator 형태로 돌려주는 메소드
25
+ # iterator는 바로 반복문 사용이 가능합니다.
26
+ for value in closet .values ():
27
+ # 해당 종류의 옷에서 선택할 수 있는 경우의 수 = 종류의 수 + 안 입기
28
+ answer *= (value + 1 )
29
+
30
+ # 아무 것도 입지 않은 경우를 제외하고 출력
31
+ print (answer - 1 )
You can’t perform that action at this time.
0 commit comments