반응형
<코드>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int T, N;
string s;
vector<string> book;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> T;
while (T--)
{
cin >> N;
for (int i = 0; i < N; i++)
{
cin >> s;
book.push_back(s);
}
sort(book.begin(), book.end());
bool ans = true;
// 정렬 후 앞뒤 번호 확인
for (int i = 1; i < N; i++)
{
string s1 = book[i - 1];
string s2 = book[i];
if (s1.size() > s2.size()) continue;
string tmp = "";
for (int j = 0; j < s1.size(); j++)
tmp += s2[j];
if (s1 == tmp)
{
ans = false;
break;
}
}
if (ans) cout << "YES" << '\n';
else cout << "NO" << '\n';
book.clear();
}
}
5052번: 전화번호 목록
첫째 줄에 테스트 케이스의 개수 t가 주어진다. (1 ≤ t ≤ 50) 각 테스트 케이스의 첫째 줄에는 전화번호의 수 n이 주어진다. (1 ≤ n ≤ 10000) 다음 n개의 줄에는 목록에 포함되어 있는 전화번호가
www.acmicpc.net
반응형
'🧩PS > 🥈Nomal' 카테고리의 다른 글
[C/C++] 백준 4358번 - 생태학 (0) | 2021.04.06 |
---|---|
[C/C++] 백준 7785번 - 회사에 있는 사람 (0) | 2021.04.06 |
[C/C++] 백준 1120번 - 문자열 (0) | 2021.04.05 |
[C/C++] 백준 11655번 - ROT13 (0) | 2021.04.05 |
[C/C++] 백준 1062번 - 가르침 (백트래킹) (0) | 2021.04.05 |