#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int o=0;
void menue()
{
printf("*******welcome!!********");
printf("===============================================================================\n");
printf(" 1:input the strings \n");
printf(" 2:sort the strings from the smallest to biggest\n");
printf(" 3:Judge whether have huiwen strings\n");
printf(" 4:close this program\n");
printf("===============================================================================\n");
printf("\n");
printf(" please input the operator you want : ");
}
int input(const int n,char *str[])
{
int i;
printf("please input the strings \n");
for(i=0;i<n;++i)
{
printf("zhe shi di %d ge zi fu chuan ",i);
scanf("%s",str[i]);
}
printf(" you have inputed %d strings, do the next you want \n", i);
return 0;
}
int sort(const int n,char *str[])
{
int i,j;
char *t;
if(o==0)
printf("You have not inputed any strings \n");
else
{
for(i=0;i<n-1;++i)
for(j=1;j<n;++j)
{
if(strcmp(str[i],str[j])>0)
{
t=str[i];
str[i]=str[j];
str[j]=t;
}
}
printf(" the strings are sorted in the order, and they are \n");
return 0;
}
int sort(const int n,char *str[])
{
int i,j;
char *t;
if(o==0)
printf("You have not inputed any strings \n");
else
{
for(i=0;i<n-1;++i)
for(j=1;j<n;++j)
{
if(strcmp(str[i],str[j])>0)
{
t=str[i];
str[i]=str[j];
str[j]=t;
}
}
printf(" the strings are sorted in the order, and they are \n");
for(i=0;i<n;++i)
{
puts(str[i]);
printf("\n");
}
}
return 0;
}
int huiwen(const int n,char *str[])
{
int i,t=1,num=0;
if(o==0)
printf("You have not inputed any strings \n");
else
{
for(i=0;i<n;++i)
{
size_t len=strlen(str[i]);
size_t j=0;
for(j=0;j<len/2;++j)
{if(str[i][j]!=str[i][len-j-1])
t=0;
}
if(t==1)
{printf("%s is hui wen string\n",str[i]);
num++;
}
t=1;
}
if(num==0)
printf("there are no huiwen string inside \n");
}
return 0;
}
int main(void)
{
int num,op,g;
printf("how many strings you want to input \n");
scanf("%d",&num);
const int Num=num;
char *str[Num];
char p[Num][100000];
for(g=0;g<Num;++g)
{
str[g]=p[g];
}
menue();
while(1)
{
scanf("%d",&op);
switch(op)
{
case 1:
input(Num,str);
o++;
break;
case 2:
sort(Num,str);
break;
case 3:
huiwen(Num,str);
break;
case 4:
exit(0);
break;
default:
printf("you input wrong opeartor \n");
break;
}
}
return 0;
}
这个是用C写的。
#include<stdlib.h>
#include<string.h>
int o=0;
void menue()
{
printf("*******welcome!!********");
printf("===============================================================================\n");
printf(" 1:input the strings \n");
printf(" 2:sort the strings from the smallest to biggest\n");
printf(" 3:Judge whether have huiwen strings\n");
printf(" 4:close this program\n");
printf("===============================================================================\n");
printf("\n");
printf(" please input the operator you want : ");
}
int input(const int n,char *str[])
{
int i;
printf("please input the strings \n");
for(i=0;i<n;++i)
{
printf("zhe shi di %d ge zi fu chuan ",i);
scanf("%s",str[i]);
}
printf(" you have inputed %d strings, do the next you want \n", i);
return 0;
}
int sort(const int n,char *str[])
{
int i,j;
char *t;
if(o==0)
printf("You have not inputed any strings \n");
else
{
for(i=0;i<n-1;++i)
for(j=1;j<n;++j)
{
if(strcmp(str[i],str[j])>0)
{
t=str[i];
str[i]=str[j];
str[j]=t;
}
}
printf(" the strings are sorted in the order, and they are \n");
return 0;
}
int sort(const int n,char *str[])
{
int i,j;
char *t;
if(o==0)
printf("You have not inputed any strings \n");
else
{
for(i=0;i<n-1;++i)
for(j=1;j<n;++j)
{
if(strcmp(str[i],str[j])>0)
{
t=str[i];
str[i]=str[j];
str[j]=t;
}
}
printf(" the strings are sorted in the order, and they are \n");
for(i=0;i<n;++i)
{
puts(str[i]);
printf("\n");
}
}
return 0;
}
int huiwen(const int n,char *str[])
{
int i,t=1,num=0;
if(o==0)
printf("You have not inputed any strings \n");
else
{
for(i=0;i<n;++i)
{
size_t len=strlen(str[i]);
size_t j=0;
for(j=0;j<len/2;++j)
{if(str[i][j]!=str[i][len-j-1])
t=0;
}
if(t==1)
{printf("%s is hui wen string\n",str[i]);
num++;
}
t=1;
}
if(num==0)
printf("there are no huiwen string inside \n");
}
return 0;
}
int main(void)
{
int num,op,g;
printf("how many strings you want to input \n");
scanf("%d",&num);
const int Num=num;
char *str[Num];
char p[Num][100000];
for(g=0;g<Num;++g)
{
str[g]=p[g];
}
menue();
while(1)
{
scanf("%d",&op);
switch(op)
{
case 1:
input(Num,str);
o++;
break;
case 2:
sort(Num,str);
break;
case 3:
huiwen(Num,str);
break;
case 4:
exit(0);
break;
default:
printf("you input wrong opeartor \n");
break;
}
}
return 0;
}
这个是用C写的。
想抽苏烟了。