vue是什么軟件 C語言,在字符串中找到最長單詞?
C語言,在字符串中找到最長單詞?要實現(xiàn)這個功能,需要遵循以下步驟:1、確定分詞符,一般為空格和標點符號,根據(jù)題目的情況來確定標點符號是否包含在單詞中。假設(shè)這個詞不包括標點符號,也就是說,它是由所有字母
C語言,在字符串中找到最長單詞?
要實現(xiàn)這個功能,需要遵循以下步驟:1、確定分詞符,一般為空格和標點符號,根據(jù)題目的情況來確定標點符號是否包含在單詞中。假設(shè)這個詞不包括標點符號,也就是說,它是由所有字母組成的。2根據(jù)以上特點,讀一個字3,計算字長4,與當(dāng)前最大字長max(初始值為0)比較,如果大于max,則記錄當(dāng)前字,將其長度賦給Max5,重復(fù)2-4,直到讀完字(到字符串末尾)。6輸出最長單詞長度和單詞7。常規(guī):包括。H>#包含<string。H>#define m 1000 int main(){int low//單詞int high的起始下標//單詞int i的結(jié)束位置//循環(huán)變量int count//計算最長單詞int temp的長度//中間變量int low temp int high temp char P[m]//具有多個單詞的字符指針get(P)count=0 low=0高=0為(I=0 I< strlen(P)I){temp=0低 emp=I而(P[I]!=“”&;P[i]!=“ ”)//P[i]!=space{temp I}high{temp=I-1 if(temp> count){count=temp low=low{temp high=high}}for(I=low I<=high I){putchar(p[I])}return 0}
C語言用函數(shù)求字符串中最長單詞?
#include<stdio.h>
#include<string.h>
int main()
{
charstr[100
]獲?。╯tr)
void findLongest(char str[])
findLongest(str)
return 0
}
void findLongest(char str[])
{
int currLen=0,maxLen=0,currStart=0,MaxStart=0
int I=0,j=0
對于(I=0str[I]I)
{
if((str I]>=“a”&&&str I]<=“Z”);(str[I]>=“a”)“&&;STR[i]<=“Z”
{
if(currlen==0)//當(dāng)前長度等于0時,表示剛搜索到一個單詞,此時的位置是
currstart=I//新詞的開頭
currlen
}
If(currlen>maxlen)//如果當(dāng)前詞的長度大于最大值,則賦值
{
maxlen=currlen
maxstart=currstart
}
If(STR[I]=”)//遇到空格,即消息已經(jīng)結(jié)束了。
{
currLen=0
}
}
對于(j=MaxStartj<MaxStart maxLenj)
printf(%c,str[j])
}