九度 1099:后缀子串排序
2017-06-22 18:31
190 查看
题目描述:
对于一个字符串,将其后缀子串进行排序,例如grain
其子串有:
grain
rain
ain
in
n
然后对各子串按字典顺序排序,即:
ain,grain,in,n,rain
输入:
每个案例为一行字符串。
输出:
将子串排序输出
样例输入:
样例输出:
数据很烦人,多组
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
using namespace std;
bool cmp(string s1,string s2){
return s1<=s2;
}
int main(){
char s[1000];
while(cin>>s) {
string a[1000];
int cnt=0;
for(int i=0;i<strlen(s);i++){
string str="";
for(int j=i;j<strlen(s);j++){
str+=s[j];
}
a[cnt++]=str;
}
sort(a,a+cnt,cmp);
for(int i=0;i<cnt;i++){
cout<<a[i]<<endl;
}
}
return 0;
}
对于一个字符串,将其后缀子串进行排序,例如grain
其子串有:
grain
rain
ain
in
n
然后对各子串按字典顺序排序,即:
ain,grain,in,n,rain
输入:
每个案例为一行字符串。
输出:
将子串排序输出
样例输入:
grain
样例输出:
ain grain in n rain
数据很烦人,多组
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
using namespace std;
bool cmp(string s1,string s2){
return s1<=s2;
}
int main(){
char s[1000];
while(cin>>s) {
string a[1000];
int cnt=0;
for(int i=0;i<strlen(s);i++){
string str="";
for(int j=i;j<strlen(s);j++){
str+=s[j];
}
a[cnt++]=str;
}
sort(a,a+cnt,cmp);
for(int i=0;i<cnt;i++){
cout<<a[i]<<endl;
}
}
return 0;
}
相关文章推荐
- 九度oj 题目1099:后缀子串排序
- 九度OJ-1099:后缀子串排序
- 九度OJ1099:后缀子串排序解题报告
- 九度OJ 1099:后缀子串排序 (排序)
- 九度题目1099:后缀子串排序
- 九度OJ 题目1099:后缀子串排序
- 九度OJ 1099 后缀子串排序
- 九度OJ 1099:后缀子串排序 (排序)
- <九度 OJ>题目1099:后缀子串排序
- 九度OJ 1099 后缀子串排序 JAVA
- 【九度】题目1099:后缀子串排序
- 题目1099:后缀子串排序
- 九度OJ—题目1099:后缀子串排序
- 题目1099:后缀子串排序
- 九度oj 1099 后缀子串排序
- jobdu 题目1099:后缀子串排序
- 题目1099:后缀子串排序(qsort函数自定义cmp函数)
- 题目1099:后缀子串排序 C++\Java
- 后缀子串排序
- 后缀子串排序(后缀数组) - 上海交通大学计算机历年考研复试上机题