#include <iostream.h>
void main()
{
cout<<"the longest code in the world!"<<endl
cout<<"the longest code in the world!"<<endl
cout<<"the longest code in the world!"<<endl
cout<<"the longest code in the world!"<<endl
cout<<"the longest code in the world!"<<endl
cout<<"the longest code in the world!"<<endl//以下重复999999999999999999999999...次
}
#include "stdio.h"#include "windows.h"
main()
{
int lastmaxlen = 0 //历史最长单词单词长度
int length=0
char str[] = "sdfsdfdsaaaaaaaaaaaaasddddddddd asdfsdfsdfdsf sdfsdfsdfsd sdfsd sdfsdfsdfsdfsdfsdfsdf "//语句
char *p=str
char *start=str//指向单词开头的指针
char buf[1024]
int count=0
while(*p!='\0')
{
if(*p==' ')
{
printf("count=%d\n ",count)
if(count>lastmaxlen){//如果当前单词的长度大于以前最长的单词
lastmaxlen=count
memset(buf,0,1024)
memcpy(buf,start,count-1)
length=count
printf("%s\n",buf)
}
start = p+1
count=0
}
count++
p++
}
if(count>lastmaxlen){
lastmaxlen=count
memset(buf,0,1024)
memcpy(buf,start,count-1)
length=count
}
printf("longest word is:'%s',length=%d\n",buf,length)
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)