老
老迟
Unregistered / Unconfirmed
GUEST, unregistred user!
#include<string.h>
#include<stdio.h>
main(int argc,char *argv){
char *a[20]={"Good","Bad","hat","cat","cap","thin","fat","big","tiny","Chi","X
ian","mine","tree","row","new","add","base","dog","egg","spy"};
int i,t;
char f[]={"-f"},s[]={"-s"},r[]={"-r"};
for(i=1;i<argc;i++){
if(strcmp(argv,f)==0)f1(a);
else
if(strcmp(argv,r)==0)f2(a);
else
if(strcmp(argv,s)>0){
t=strcmp(*(argv+i),s)-48;
f3(a,t);
}
}
for(i=0;i<20;i++)
printf("%s/n",a);
}
f1(char *a[20]){
int i,j,k;
char *temp;
for(i=0;i<19;i++){
k=i;
for(j=i+1;j<20;j++)
if(strcmp(a[k],a[j])>0)k=j;
if(k!=i)
{temp=a;
a=a[k];
a[k]=temp;}
}
}要求:扩展排序程序,接受命令行参数,待排序字符集(〉20)事先设定,用二维数组储存
,排序算法自定。-f忽略大小写,-r逆序排序-s指定排序起始字符如-s2
#include<stdio.h>
main(int argc,char *argv){
char *a[20]={"Good","Bad","hat","cat","cap","thin","fat","big","tiny","Chi","X
ian","mine","tree","row","new","add","base","dog","egg","spy"};
int i,t;
char f[]={"-f"},s[]={"-s"},r[]={"-r"};
for(i=1;i<argc;i++){
if(strcmp(argv,f)==0)f1(a);
else
if(strcmp(argv,r)==0)f2(a);
else
if(strcmp(argv,s)>0){
t=strcmp(*(argv+i),s)-48;
f3(a,t);
}
}
for(i=0;i<20;i++)
printf("%s/n",a);
}
f1(char *a[20]){
int i,j,k;
char *temp;
for(i=0;i<19;i++){
k=i;
for(j=i+1;j<20;j++)
if(strcmp(a[k],a[j])>0)k=j;
if(k!=i)
{temp=a;
a=a[k];
a[k]=temp;}
}
}要求:扩展排序程序,接受命令行参数,待排序字符集(〉20)事先设定,用二维数组储存
,排序算法自定。-f忽略大小写,-r逆序排序-s指定排序起始字符如-s2