25: longest and shortest word, 25: Word

Source: Internet
Author: User

25: longest and shortest word, 25: Word
25: longest and shortest word

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

Enter one sentence (no more than 200 words, each word cannot exceed 100 characters), including only letters, spaces, and commas. A word consists of at least one consecutive letter. Spaces and commas are the intervals between words.

Output 1st longest words and 1st shortest words.

Input
One sentence.
Output
Two rows of output:
The first longest word in the first row.
The first shortest word in the first row.
Sample Input
I am studying Programming language C in Peking University
Sample output
ProgrammingI
Prompt
If all words have the same length, the first word is both the longest word and the shortest word.
Source
Exercise (12-2)
 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 using namespace std; 6 int max_=-1; 7 int max_begin; 8 int max_end; 9 int min_=10000;10 int min_begin;11 int min_end;12 char a[1000001];13 int b[1000001];14 int main()15 {16     int tot=0;17     gets(a);18     int l=strlen(a);19     for(int i=0;i<=l;i++)20     {21         int begin=i;22         if((a[i]>=65&&a[i]<=90)||(a[i]>=97&&a[i]<=122))23         {24             tot++;25         }26         else27         {28             if(tot>max_)29             {30                 max_=tot;31                 max_begin=i-tot;32                 max_end=i;33             }34              if(tot<min_&&tot!=0)35             {36                 min_=tot;37                 min_begin=i-tot;38                 min_end=i;39             40             }41             tot=0;42         }43     }44     for(int i=max_begin;i<=max_end-1;i++)cout<<a[i];45     cout<<endl;46     for(int j=min_begin;j<=min_end-1;j++)cout<<a[j];47     return 0;48 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.