Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- widget
- composable architecture
- 멋쟁이사자처럼
- widgetkit
- 웹
- 영남대
- 문법
- 1일1알골
- 위젯킷
- uikit
- swift concurrency
- 대외활동
- 컴퓨터그래픽스
- 알고리즘
- 리액트
- SwiftUI
- dispatchqueue
- Protocol
- cs
- 네트워크
- spritekit
- 후기
- Swift
- 스위프트
- 멋사
- 백준
- c++
- 스유
- TCA
- 운영체제
Archives
- Today
- Total
맛동산이
(백준 14425) 문자열 집합 본문
문제
https://www.acmicpc.net/problem/14425
14425번: 문자열 집합
첫째 줄에 문자열의 개수 N과 M (1 ≤ N ≤ 10,000, 1 ≤ M ≤ 10,000)이 주어진다. 다음 N개의 줄에는 집합 S에 포함되어 있는 문자열들이 주어진다. 다음 M개의 줄에는 검사해야 하는 문자열들이 주어
www.acmicpc.net
코드
첫번째 코드
#include <set>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
int n;
int m;
cin >> n;
cin >> m;
set<string> arr1;
vector<string> arr2(n);
string u;
int count = 0;
for (int a = 0; a < n; a++)
{
cin >> u;
arr1.insert(u);
}
for (int a = 0; a < m; a++)
{
cin >> arr2[a];
if (arr1.find(arr2[a]) != arr1.end())
{
count++;
}
}
cout << count;
}
첫번째 코드에서는 set을 사용했는데, 첫번째 문자열을 백터에 저장하고 두번째 입력값을 set에 저장하였는데,
잘 되다가, outofbound가 발생하였다. 아마 백터 문제인것 같아서 백터를 삭제하고 그냥 string으로 바로 입력받아서 비교하게 하였다.
정답코드
#include <set>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
int n;
int m;
cin >> n;
cin >> m;
set<string> arr1;
string arr2;
string u;
int count = 0;
for (int a = 0; a < n; a++)
{
cin >> u;
arr1.insert(u);
}
for (int a = 0; a < m; a++)
{
cin >> arr2;
if (arr1.find(arr2) != arr1.end())
{
count++;
}
}
cout << count;
}
완료!
반응형
'알고리즘 > 백준' 카테고리의 다른 글
(백준 1764) 듣보잡 (0) | 2022.06.29 |
---|---|
(백준 1269) 대칭 차집합 (0) | 2022.06.29 |
(백준 10815) 숫자 카드 (0) | 2022.06.26 |
(백준 10814) 나이순 정렬 (0) | 2022.06.25 |
백준 1436 영화감독 숀 (0) | 2022.06.17 |