标题:太简单了!
只看楼主
303770957
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:6
帖 子:838
专家分:2125
注 册:2005-9-10
 问题点数:0 回复次数:0 
太简单了!
程序清单:
 #include "stdio.h"
#include "string.h"
#define   Q  200
void main()
  {int k,m;
   char str[Q];
   printf("                       英文句子管理程序\n");
   printf("请输入您要处理的英文句子(注意标点符号与单词之间至少有一个空格):\n");
   gets(str);
   printf("您要进行处理的英文句子为:\n");
   puts(str);
do{printf(" \n              英文句子处理主菜单\n");
   printf("********************************************************\n");
   printf("|    1.删除该句子的前导空格、后导空格。                |\n");
   printf("|    2.删除该句子中多余的空格(单词之间只留一个空格)。|\n");
   printf("|    3.统计该句子中某个单词出现的频率 。               |\n");
   printf("|    4.查找并替换某个单词。                            |\n");
   printf("|    5.安全安全退出管理。                              |\n");
   printf("********************************************************\n");
   printf("请选择您要执行的操作(1--5):");
   scanf("%d",&k);
   switch(k)
    {case 1:{ int i,h,num=0;
              i=strlen(str);
              do{i--;
                 }while(str[i]==' ');
              str[i+1]='\0';
                i=0;
             while(str[i]==' ') i++;
               if(str[i]!='\0') num=1; h=i;m=i;
               while(str[i]!='\0')
                {if(i>0 && str[i]==' ' && str[i-1]!=' ')
                  num++;i++;}
                 printf("经过功能<1>处理后的英文句子为:\n");
               for(;str[h]!='\0';h++)
               printf("%c",str[h]);printf("\n");
                };break;
      case 2:{int a,q;
                printf("经过功能<2>处理后的英文句子为:\n");
                for(a=m;str[a]!='\0';)
                {if(str[a]!=' ') {printf("%c",str[a]);a++;q=0;}
                 while(str[a]==' ') {q=1;a++;}
                 if(q==1) printf(" ");
                 }
              };printf("\n"); break;
      case 3:{ int k1,k2,i=0,k=0,m;
               char str2[Q],str1[Q],*p,*q;
               printf("请输入您要统计的单词:");
               scanf("%s",str1);
              do
                {while(str[i]==' '&&i<=strlen(str)) i++;k1=i;
                 while(1)
                  {if(str[i]==' ' && str[i+1]!=' ')  break;
                   i++;
                   if(str[i]==' ' && str[i-1]!=' ') k2=i-1;
                   if(i>=strlen(str)) break;
                   };
                 p=str;
                 q=str2;
                 p+=k1;
                 for(m=k1;m<=k2;m++)
                 {*q=*p;p++;q++;}
                  *q='\0';
                 if(strcmp(str2,str1)==0) k++;
                }while(str[i]!='\0' && i<=strlen(str));
              printf("您要统计的单词%s出现了%d次.\n",str1,k);
              };break;
      case 4:{int k1,k2,i=0,k,m,x;
              char str3[Q],str4[Q];
              char str2[Q],str5[Q];
              char *p,*q;
              printf("请输入您要查找的单词:\n");
              scanf("%s",str3);
              printf("请输入您要替换的单词:\n");
              scanf("%s",str4);
              printf("经过单词替换后的英文句子为:\n");
              i=0;
              do
                {while(str[i]==' '&&i<=strlen(str)) i++;k1=i;
                 while(1)
                  {if(str[i]==' ' && str[i+1]!=' ') break;
                   i++;
                   if(str[i]==' ' && str[i-1]!=' ') k2=i-1;
                   if(i>=strlen(str)) break;
                   };
                 p=str;
                 q=str2;
                 p+=k1;
                 for(m=k1;m<=k2;m++)
                 {*q=*p;p++;q++;}
                  *q='\0';
                 if(strcmp(str2,str3)==0) printf("%s ",str4);
                 else printf("%s ",str2);
                }while(str[i]!='\0' && i<=strlen(str));
              }; break;
      default:break;}
      }while(k!=5);
     }
搜索更多相关主题的帖子: 管理程序 标点符号 英文句子 菜单 
2005-10-03 20:01



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-29267-1-1.html




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

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