• 最长最短单词c++


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

    #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]='';
    }

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

  • 相关阅读:
    数据库的......
    数据库
    XML
    网络编程
    I/O系统---流
    周结

    集合,框架
    Spring入门
    Java Wed
  • 原文地址:https://www.cnblogs.com/5t2y0/p/9229771.html
Copyright © 2020-2023  润新知