๋ฐฑ์ค€/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