标题:改错!功能是:找出最长的单词。
只看楼主
按时的飞过海
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-7-20
 问题点数:0 回复次数:2 
改错!功能是:找出最长的单词。
功能是:找出最长的单词。
请对其中2条错误语句进行修改,不允许修改总框架,算法,不增减语句
cstring='this is one of the best books'
ncount=0
cresult=SPACE(0)
DO WHILE LEN(cstring)>0
n=AT(SPACE(1),cstring)
cWord=ALLT(IIF(n=0,string,subs(cstring,1,n)))
cstring=ALLT(IIF(n=0,SPACE(0),SUBS(cstring,1,n)))
if len(cword)>ncount
ncount=ncount+1
cresult=cword
endif
enddo
wait window'最长的单词是'+cresult
谢谢!
搜索更多相关主题的帖子: 单词 改错 
2006-10-22 08:42
pogai
Rank: 1
等 级:新手上路
威 望:1
帖 子:90
专家分:0
注 册:2006-3-3
得分:0 
cstring='this is one of the best books'
ncount=0
cresult=SPACE(0)
DO WHILE LEN(cstring)>0
n=AT(SPACE(1),cstring)
cWord=ALLT(IIF(n=0,cstring,subs(cstring,1,n)))*是不是少写了一个c
cstring=ALLT(IIF(n=0,SPACE(0),SUBS(cstring,n+1)))*改了这一处
if len(cword)>len(cresult) *改了这一处
ncount=ncount+1
cresult=cword
endif
enddo
wait window'最长的单词是'+cresult

我用上面的这个程序试了下,好像得到了你要的结果。也不知道是不是真的对了!
2006-10-22 21:30
Tiger5392
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:88
帖 子:2775
专家分:2237
注 册:2006-5-17
得分:0 

2楼修改的不错,我只找到了2处错误:

cstring='this is one of the best books'
ncount=0
cresult=SPACE(0)
DO WHILE LEN(cstring)>0
n=AT(SPACE(1),cstring)
cWord=ALLT(IIF(n=0,cstring,subs(cstring,1,n))) &&第1处错误:string改为cstrint
cstring=ALLT(IIF(n=0,SPACE(0),SUBS(cstring,1+n))) &&第2处错误:,改为+
if len(cword)>ncount
ncount=ncount+1
cresult=cword
endif
enddo
wait window'最长的单词是'+cresult


感言:学以致用。 博客:http://www./blog/user14/65009/index.shtml email:Tiger5392@
2006-10-22 23:00



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




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

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