输入一个字符串,将此字符串中最长的单词输出。要求至少使用一个自定义函数。
若有多个长度相等的最长单词,输出最早出现的那个。这里规定,单词只能由大小写英文字母构成。
输入
Keywords insert, two way insertion sort,
Abstract This paper discusses three method for two way insertion
words. insert, two way sorted.
输出
insertion
discusses
insert
c语言求最长单词改变
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- fuill 2022-04-07 14:29关注
#include<stdio.h> #include<string.h> #define max 150 //句子总单词数最大值 #define lmax 25 //句子单个单词字母总数最大值 int isc(char t) //判断一个字符是不是字母 { if((t<='z'&&t>='a')||(t<='Z'&&t>='A')) return 1; else return 0; } int isw(char t[],int b,int e)//判断字符串从下标b开始到下标e是不是一个单词 { int flag=1; for(int i=b; i<=e; i++)//下标b开始到下标e,中间有不是字母的,返回 { if(isc(t[i])==0) { return 0; } } if(b>0)//不是字符串第一个字符 { if(isc(t[b-1])==0&&isc(t[e+1])==0)//下标b-1和下标e+1不是字母,返回 { return 1; } } else { if(isc(t[e+1])==0) { return 1; } } return 0; } void prin(char t[],int b,int e)//打印字符串从下标b开始到下标e之间的内容 { for(int i=b; i<=e; i++) { putchar(t[i]); } printf("\n"); } int main() { char t[max]= {' '}; char wt[max][lmax]; while(t) { gets(t); int count=0; int len=strlen(t); int Left=0,Right=0;//左指针Left,右指针Right int p1=0,p2=0,p=0;; for(Left=0; Left<len; Left++) { for(Right=0; Right<len-Left; Right++) { if(isw(t,Left,Left+Right)==1)//判断从左指针到右指针,之间是不是一个单词 { if(Right>p) { p1=Left; p2=Right; p=p2; } count ++; break; } } } prin(t,p1,p1+p2); } return 0; }
https://blog.csdn.net/weixin_44882124/article/details/123593401
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥170 如图所示配置eNSP
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效
- ¥15 悬赏!微信开发者工具报错,求帮改
- ¥20 wireshark抓不到vlan
- ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
- ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
- ¥15 stata安慰剂检验作图但是真实值不出现在图上
- ¥15 c程序不知道为什么得不到结果
- ¥15 键盘指令混乱情况下的启动盘系统重装