文章
79
粉丝
221
获赞
46
访问
198.3k
#include <iostream>
#include <string>
using namespace std;
//s1在字典里的顺序早于s2时输出小于0
int Comp(string s1, string s2) {
int i, j;
for (i = 0, j = 0; i < s1.size() && j < s2.size(); i++, j++)
if (s1[i] != s2[j])
return s1[i] - s2[j];
return s1.size() - s2.size();
}
int main() {
string s;
cin >> s;
string* st = new string[s.size()];
for (int i = 0; i < s.size(); i++) {
string temp = s.substr(i);
st[i] = temp;
for (int j = i; j > 0; j--)
if (Comp(st[j], st[j - 1]) < 0)
swap(st[j], st[j - 1]);
}
for (int i = 0; i < s.size(); i++)
cout << st[i] << endl;
return 0;
}
登录后发布评论
暂无评论,来抢沙发