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 | 29 |
30 | 31 |
Tags
- ๋งต
- ์ต๋จ ๊ฒฝ๋ก
- ์ฌ๊ท
- java
- GCP
- thymeleaf
- DP
- Reversing
- web
- ๋ถํ ์ ๋ณต
- ๋์ ํฉ
- ์ด๋ถ ํ์
- ๊ตฌํ
- c++
- ๋ฐฑํธ๋ํน
- CVE
- Spring
- JPA
- ๋ฌธ์์ด
- ์์ ์ ๋ ฌ
- dynamic debugging
- error
- dfs
- ์ฐ์ ์์ ํ
- OS
- ๋ฐ์ดํฌ์คํธ๋ผ
- ์คํ
- ์๋ฎฌ๋ ์ด์
- BFS
- ๊ทธ๋ฆฌ๋
Archives
- Today
- Total
hades
[Baekjoon] 1181๋ฒ: ๋จ์ด ์ ๋ ฌ ๋ณธ๋ฌธ
๐ฅ ๋ฌธ์
https://www.acmicpc.net/problem/1181
๐ ์ค๊ณ
1์ฐจ๋ก ๋จ์ด ๊ธธ์ด ์์ผ๋ก ์ ๋ ฌ, 2์ฐจ๋ก ์ฌ์ ์์ผ๋ก ์ ๋ ฌํ๊ณ , ์ค๋ณต์ ์ ๊ฑฐํ๋ฉด ๋๋ค.
์ค๋ณต์ ์ ๊ฑฐํ๊ธฐ ์ํด unique์ erase๋ฅผ ์ฌ์ฉํ๋ค. unique๋ ์ค๋ณต์ด ์๋ ์์๋ค์ ๋ฒกํฐ์ ๋์ผ๋ก ๋ณด๋ด๊ณ , ์ค๋ณต ์์๋ค์ ์์์ ์ ๋ฐํํ๋ค. erase๋ erase(iterator first, iterator last); ์์ [first, last) ๋ฒ์์ ์์๋ฅผ ์ ๊ฑฐํ๋ค.
์ค๋ณต์ ์ ๊ฑฐํ์ผ๋ฏ๋ก, ๋จ์์๋ ์์์ ๊ฐ์๋ n์ด ์๋ ์ ์์ผ๋ฏ๋ก ์ฃผ์ํ๋ค.
๐ ํ์ด
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int n;
string s;
vector<string> words;
bool compare(string a, string b) {
if (a.length() < b.length()) {
return true;
}
else if (a.length() == b.length()) {
return a < b;
}
else {
return false;
}
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
words.push_back(s);
}
sort(words.begin(), words.end(), compare);
words.erase(unique(words.begin(), words.end()), words.end());
for (int i = 0; i < words.size(); i++) {
cout << words[i] << "\n";
}
return 0;
}
'๐ PS > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Baekjoon] 1916๋ฒ: ์ต์๋น์ฉ ๊ตฌํ๊ธฐ (0) | 2024.08.06 |
---|---|
[Baekjoon] 1753๋ฒ: ์ต๋จ๊ฒฝ๋ก (0) | 2024.08.05 |
[Baekjoon] 1504๋ฒ: ํน์ ํ ์ต๋จ ๊ฒฝ๋ก (0) | 2024.08.03 |
[Baekjoon] 1238๋ฒ: ํํฐ (0) | 2024.08.03 |
[Baekjoon] 1629๋ฒ: ๊ณฑ์ (0) | 2024.08.03 |