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
- 문자열
- 스택
- 다익스트라
- Team Fortress 2
- 우선순위 큐
- 재귀
- 백트래킹
- ue5
- 누적 합
- 다이나믹 프로그래밍
- 그래프
- 그리디 알고리즘
- 자료구조
- 트리
- XR Interaction Toolkit
- 유니티
- DFS
- 브루트포스
- 투 포인터
- 정렬
- 구현
- 알고리즘
- 시뮬레이션
- c++
- BFS
- 유니온 파인드
- 백준
- VR
- 수학
- Unreal Engine 5
Archives
- Today
- Total
1일1알
백준 2866번 문자열 잘라내기 C++ 본문
https://www.acmicpc.net/problem/2866
2866번: 문자열 잘라내기
첫 번째 줄에는 테이블의 행의 개수와 열의 개수인 R과 C가 주어진다. (2 ≤ R, C ≤ 1000) 이후 R줄에 걸쳐서 C개의 알파벳 소문자가 주어진다. 가장 처음에 주어지는 테이블에는 열을 읽어서 문자
www.acmicpc.net
루프마다 문자열을 새로 만들면 시간초과가 나서 처음에 전체 문자열을 만들고 substr로 구함
#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 r, c;
vector<vector<char>> table;
vector<string> strs;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> r >> c;
table = vector<vector<char>>(r, vector<char>(c));
strs = vector<string>(c, "");
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin >> table[i][j];
}
}
for (int j = 0; j < c; j++) {
for (int i = 0; i < r; i++) {
strs[j] += table[i][j];
}
}
bool repeat = true;
int ans = 0;
for (int i = 1; i < r; i++) {
set<string> s;
for (int j = 0; j < c; j++) {
string str = strs[j].substr(i, r);
s.insert(str);
}
if (s.size() != c) {
break;
}
ans++;
}
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 13565번 침투 C++ (0) | 2023.01.25 |
---|---|
백준 2784번 가로 세로 퍼즐 C++ (0) | 2023.01.24 |
백준 1138번 한 줄로 서기 C++ (0) | 2023.01.19 |
백준 26215번 눈 치우기 C++ (0) | 2023.01.18 |
백준 14940번 쉬운 최단거리 C++ (0) | 2023.01.17 |