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
- 브루트포스
- 투 포인터
- 재귀
- 유니티
- XR Interaction Toolkit
- 문자열
- 다익스트라
- 유니온 파인드
- 정렬
- 우선순위 큐
- Unreal Engine 5
- 누적 합
- 그리디 알고리즘
- BFS
- 스택
- Team Fortress 2
- 백트래킹
- 다이나믹 프로그래밍
- 트리
- 시뮬레이션
- VR
- 자료구조
- 그래프
- 백준
- ue5
- DFS
- 수학
- 알고리즘
- 구현
- c++
Archives
- Today
- Total
1일1알
백준 1411번 비슷한 단어 C++ 본문
https://www.acmicpc.net/problem/1411
1411번: 비슷한 단어
첫째 줄에 단어의 개수 N이 주어진다. 둘째 줄부터 N개의 줄에 한 줄에 하나씩 단어가 주어진다. 단어의 길이는 최대 50이고, N은 100보다 작거나 같은 자연수이다. 모든 단어의 길이는 같고, 중복
www.acmicpc.net
문자열끼리 하나씩 전부 검사한다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n;
vector<string> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
v = vector<string>(n);
int ans = 0;
for (int i = 0; i < n; i++) cin >> v[i];
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
map<char, char> mp;
set<char> st;
string str1 = v[i];
string str2 = v[j];
bool sim = true;
for (int k = 0; k < str1.length(); k++) {
auto itm = mp.find(str1[k]);
auto its = st.find(str2[k]);
if (itm == mp.end()) {
if (its != st.end()) {
sim = false;
}
mp[str1[k]] = str2[k];
st.insert(str2[k]);
}
else {
if (mp[str1[k]] == str2[k]) continue;
sim = false;
}
}
if (sim) {
ans++;
}
}
}
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 16168번 퍼레이드 C++ (0) | 2023.03.08 |
---|---|
백준 16398번 행성 연결 C++ (0) | 2023.03.07 |
백준 7795번 먹을 것인가 먹힐 것인가 C++ (0) | 2023.03.04 |
백준 22233번 가희와 키워드 C++ (0) | 2023.03.03 |
백준 2942번 퍼거슨과 사과 C++ (0) | 2023.03.02 |