- 笨笨的单词排序
- 2015-09-04 19:00:19 @
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
vector<string>v2;
string v1;
string b;
int n,m,i,j;
cin>>v1;
cin>>n;
for(i=0;i<n;i++){
cin>>b;
v2.push_back(b);
}
cin>>m;
while(m==1){
for(j=0;j<26;j++)
for(i=0;i<n;i++){
if(v1[j]==v2[i][0]) cout<<v2[i]<<endl;
}
m=8;
}
while(m==0){
for(j=25;j>=0;j--)
for(i=0;i<n;i++){
if(v1[j]==v2[i][0]) cout<<v2[i]<<endl;
}
m=8;
}
return 0;
}
2 条评论
-
TLECODE LV 7 @ 2016-09-15 16:31:18
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<map>
using namespace std;
map<char,int>px;
struct word{
char w[260];
}m[1005];
int o;
bool strcmp(char *a,char *b){
int n=strlen(a),m=strlen(b),i,j;
for(i=0,j=0;i<n&&j<m;i++,j++){
if(a[i]!=b[j]){
return o?px[a[i]]<px[b[j]]:px[a[i]]>px[b[j]];
}
}
return o?n<m:n>m;
}
bool cmp(word a,word b){
return strcmp(a.w,b.w);
}
int main(){
int i,n;
for(i=0;i<26;i++){
px[getchar()]=i;
}
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%s\n",m[i].w);
}
scanf("%d",&o);
sort(m,m+n,cmp);
for(i=0;i<n;i++){
printf("%s\n",m[i].w);
}
return 0;
} -
2015-09-12 11:51:35@
I don't kmow
- 1