Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

60-xxubin04 #227

Merged
merged 2 commits into from
Oct 8, 2024
Merged

60-xxubin04 #227

merged 2 commits into from
Oct 8, 2024

Conversation

xxubin04
Copy link
Member

@xxubin04 xxubin04 commented Sep 22, 2024

πŸ”— 문제 링크

λ°±μ€€ 1764: λ“£λ³΄μž‘


βœ”οΈ μ†Œμš”λœ μ‹œκ°„

10λΆ„


✨ μˆ˜λ„ μ½”λ“œ

1. 문제 이해

N만큼의 듀어보지 λͺ»ν•œ μ‚¬λžŒ 이름을 μž…λ ₯λ°›λŠ”λ‹€.
M만큼의 보도 λͺ»ν•œ μ‚¬λžŒ 이름을 μž…λ ₯λ°›λŠ”λ‹€.

μ΄λ•Œ, set에 이름듀을 μ €μž₯ν•¨μœΌλ‘œμ¨ λ‚˜μ€‘μ— 듣도 보도 λͺ»ν•œ μ‚¬λžŒμ˜ 이름을 좜λ ₯ν•˜λŠ”λ° μš©μ΄ν•˜λ‹€.


2. 전체 μ½”λ“œ

input = open(0).readline

N, M = map(int, input().split())
never_listen = set()  
never_seen = set()  

for n in range(N):
    never_listen.add(input().rstrip())  # 듀어보지 λͺ»ν•œ μ‚¬λžŒ μ €μž₯

for m in range(M):
    never_seen.add(input().rstrip())  # 보도 λͺ»ν•œ μ‚¬λžŒ μ €μž₯

never_listen_seen = sorted(list(never_listen & never_seen))  # 듣도 보도 λͺ»ν•œ μ‚¬λžŒ μ €μž₯

print(len(never_listen_seen))

for i in never_listen_seen:
    print(i)

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

λ„ˆλ¬΄ μ‰¬μš΄ 문제λ₯Ό ν’€μ—ˆλ„€μš”..ν•˜ν•˜..
λ‹€μŒμ—” μ’€ 더 μ–΄λ €μš΄ 문제λ₯Ό ν’€κ² μŠ΅λ‹ˆλ‹€..!

Copy link
Collaborator

@9kyo-hwang 9kyo-hwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set을 μ‚¬μš©ν•˜λ©΄ μ‰½κ²Œ ꡬ할 수 μžˆλŠ” μ‹¬ν”Œν•œ 문제죠~
μ˜ˆμ „μ— C++둜 ν’€μ—ˆμ—ˆλŠ”λ°, set 2개λ₯Ό μ‚¬μš©ν•˜κ³  κ΅μ§‘ν•©μœΌλ‘œ κ±°λ₯΄λŠ” λ°©μ‹λ³΄λ‹€λŠ” never_listen을 set에 넣은 λ’€ never_listen이 될 이름듀을 ν•˜λ‚˜μ”© μž…λ ₯λ°›μœΌλ©° never_listen에 "μ—†λ‹€λ©΄" list에 λ„£λŠ” μ‹μœΌλ‘œ 검사해 필터링 된 μΉœκ΅¬λ“€λ§Œ μ •λ ¬ν•΄μ„œ 좜λ ₯ν•˜λŠ” 게 더 λΉ¨λΌμ„œ κ·Έλ ‡κ²Œ ν’€μ—ˆλ˜ 기얡이 μžˆλ„€μš”.

#include <iostream>
#include <unordered_set>
#include <algorithm>

using namespace std;

int main()
{
    cin.tie(nullptr)->sync_with_stdio(false);
    
    int N, M; cin >> N >> M;
    
    unordered_set<string> NeverSeen;
    string Name;
    while(N--)
    {
        cin >> Name;
        NeverSeen.emplace(Name);
    }
    
    vector<string> OffBrand;
    while(M--)
    {
        cin >> Name;
        if(NeverSeen.count(Name))
        {
            OffBrand.emplace_back(Name);
        }
    }
    sort(OffBrand.begin(), OffBrand.end());
    
    cout << OffBrand.size() << "\n";
    for(const string& Ans : OffBrand)
    {
        cout << Ans << "\n";
    }
    
    return 0;
}

for m in range(M):
never_seen.add(input().rstrip())

never_listen_seen = sorted(list(never_listen & never_seen))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ˜€μ˜€μ˜Ήγ…‡..!
set을 μ΄λ ‡κ²Œ μ‚¬μš©ν•˜λ©΄ ꡐ집합이 λ˜λŠ”κ΅°μš”?
재밌고 μŒˆλ½•ν•œκ±° μ•Œμ•„κ°‘λ‹ˆλ‹€!

Copy link
Member

@gjsk132 gjsk132 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ €λŠ” dict으둜 ν•΄μ„œ 이름 횟수 cnt ν•΄μ€¬μŠ΅λ‹ˆλ‹Ή!

from collections import defaultdict

input = open("input.txt").readline

listen, watch = map(int,input().split())

answer = []

cnt = defaultdict(int)

for i in range(listen+watch):
    cnt[input().rstrip()] += 1

for k, v in cnt.items():
    if v == 2:
        answer.append(k)

print(len(answer))
for a in sorted(answer):
    print(a)

Copy link
Collaborator

@mjj111 mjj111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정말 듣지도 보지도 λͺ»ν•œ λ¬Έμ œλ‘œκ΅°μš”!
νŒŒμ΄μ¬μ—μ„œλŠ” & μ—°μ‚° μ΄ν›„λ‘œλŠ” set이 λ°˜ν™˜λ˜λ§Œ,
sorted λ©”μ„œλ“œ μ΄ν›„λ‘œ list κ°€ λ°˜ν™˜λ˜μ„œ μ•„λž˜μ™€ 같이 μž‘μ„±μ΄ κ°€λŠ₯ν•©λ‹ˆλ‹€ !

n, m = map(int, input().split())

no_see = set()
for _ in range(n):
    no_see.add(input())


no_hear = set()
for _ in range(m):
    no_hear.add(input()) 

no_see_hear = no_see & no_hear
print(len(no_see_hear))
for i in sorted(no_see_hear): 
    print(i)

@9kyo-hwang 9kyo-hwang merged commit e5f1289 into AlgoLeadMe:main Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants