๋ฐฑ์ค/C++
[๋ฐฑ์ค/C++] 11656๋ฒ ์ ๋ฏธ์ฌ ๋ฐฐ์ด
yulee_to
2022. 11. 14. 19:21
๐ค๋ฌธ์ ์ดํด
๋ฌธ์์ด์ ์ ๋ฌธ์๋ฅผ ํ๋์ฉ ์ฐจ๋ก๋ก ์์ค ๋ฌธ์์ด๋ค์ ์ฌ์ ์์ผ๋ก ์ ๋ ฌํ์ฌ ์ถ๋ ฅํ๋ ๋ฌธ์ ์ด๋ค.
๐ฅํ์ด๐ฅ
So Easyํ ๋ฌธ์ !
์ด์ค for๋ฌธ์ผ๋ก ์์์๋ถํฐ ๋ฌธ์๋ฅผ ํ๋์ฉ ์ง์ด ๋ฌธ์์ด์ vector์ ๋ฃ์ด์ฃผ๊ณ sortํจ์๋ก ๊ทธ vector ๋ฐฐ์ด์ ์ ๋ ฌํด์ฃผ๋ฉด ์๋์ผ๋ก ์ฌ์ ์์ผ๋ก ์ ๋ ฌ๋๋ค. ๊ทธ๋ฌ๊ณ ๋์ ๋ฐฐ์ด์ ์ ์ฅ๋ ๋ฌธ์์ด๋ค์ ์ฐจ๋ก๋๋ก ์ถ๋ ฅํด์ฃผ๋ฉด ๋!
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<string> strs;
string s;
int main() {
cin.tie(nullptr);
cout.tie(nullptr);
ios::sync_with_stdio(false);
cin >> s;
for (int i = 0; i < s.size(); i++) {
string tmp;
for (int j = i; j < s.size(); j++) {
tmp += s[j];
}
strs.push_back(tmp);
}
sort(strs.begin(), strs.end());
for (int i = 0; i < strs.size(); i++) {
cout << strs[i] << "\n";
}
}
728x90