| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 827 人关注过本帖
标题:大学一年级题目,求大神围观下
只看楼主 加入收藏
fl8962
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:14
帖 子:539
专家分:2471
注 册:2012-10-17
收藏
得分:0 
#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写的。

想抽苏烟了。
2014-02-20 00:45
快速回复:大学一年级题目,求大神围观下
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028682 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved