码迷,mamicode.com
首页 > 编程语言 > 详细

最长最短单词c++

时间:2018-06-26 17:19:28      阅读:296      评论:0      收藏:0      [点我收藏+]

标签:mes   har   names   clu   word   line   cin.get   its   end   

本人只是一个菜鸡。这还是要感谢一个大佬的帮助才能够写出来。分享给大家。

#include<bits/stdc++.h>
using namespace std;
int main()
{
char a[20000];
char wlong[200];
char wshort[200],word[200];
int numlong=0,numshort=100;
int i,n,l,k,cl;
l=0;
k=0;
cin.getline(a,20000);
n=strlen(a);
for(i=0;i<=n;i++)
{
if(a[i]!=‘ ‘&&a[i]!=‘,‘&&a[i]!=0)
{
l++;
word[k]=a[i];
k++;
}
if(a[i]==‘ ‘||a[i]==‘,‘||a[i]==0)
{
if(l>numlong)
{
numlong=l;
strcpy(wlong,word);
}
if(l>0&&l<numshort)
{
numshort=l;
strcpy(wshort,word);
}
l=0;
k=0;
for(cl=0;cl<=200;cl++)
word[cl]=‘\0‘;
}

}
cout<<wlong<<endl;
cout<<wshort;
return 0;
}

最长最短单词c++

标签:mes   har   names   clu   word   line   cin.get   its   end   

原文地址:https://www.cnblogs.com/5t2y0/p/9229771.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!