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
- c++
- 수학
- 브루트포스
- Team Fortress 2
- 문자열
- 구현
- ue5
- 유니티
- BFS
- 다이나믹 프로그래밍
- 그래프
- XR Interaction Toolkit
- 다익스트라
- VR
- 백준
- 시뮬레이션
- 그리디 알고리즘
- Unreal Engine 5
- 투 포인터
- 누적 합
- 자료구조
- 알고리즘
- 트리
- 스택
- 우선순위 큐
- 정렬
- 백트래킹
- 재귀
- DFS
- 유니온 파인드
Archives
- Today
- Total
1일1알
백준 1235번 학생 번호 C++ 본문
뒤에서부터 substr를 이용해서 부분 문자열을 추출하면서 set에 넣어서 넣은 만큼 있으면 모두 다른 것이므로 그때가 서로 다른 최소의 길이이다.
#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 <unordered_map>
#include <unordered_set>
#include <iomanip>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<string> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
int idx = v[0].length() - 1;
int ans = 0;
int cnt = 1;
for (int i = idx; i >= 0; i--) {
set<string> s;
for (int j = 0; j < n; j++) {
s.insert(v[j].substr(i, cnt));
}
if (s.size() != n) {
cnt++;
continue;
}
ans = idx - i + 1;
break;
}
cout << ans;
};
'알고리즘' 카테고리의 다른 글
백준 1251번 단어 나누기 C++ (0) | 2022.04.18 |
---|---|
백준 1244번 스위치 켜고 끄기 C++ (0) | 2022.04.17 |
백준 1213번 팰린드롬 만들기 C++ (0) | 2022.04.15 |
백준 1113번 수영장 만들기 C++ (0) | 2022.04.14 |
백준 1195번 킥다운 C++ (0) | 2022.04.12 |