Subject description:
Given a string composed of several words, smaller than the length of the string 500, between words and words are separated by spaces, wherein the obtaining the longest shortest word
Enter a description:
Less than the string length 500
Output Description:
2 output lines, one word per line, the longest first line of output words, the shortest word in the second output line, if a plurality of shortest longest word of the same length, the first occurrence of the output
Sample input:
I play the leading man who else
Sample output:
leading
I
1 #include<iostream> 2 using namespace std; 3 int main(){ 4 char m[1000]; 5 int i=0,word=0,p=0,q=0; 6 int max=0,min=500; 7 gets(m); 8 while(m[i]!='\0'){ 9 while(m[i]!=' '&&m[i]!='\0'){ 10 i++; 11 word++; 12 } 13 if(word>max){ 14 max=word; 15 p=i-word; 16 } 17 if(word<min){ 18 min=word; 19 q=i-word; 20 } 21 while(m[i]==' '){ 22 i++; 23 word=0; 24 } 25 } 26 for(i=p;i<p+max;i++){ 27 cout<<m[i]; 28 } 29 cout<<endl; 30 for(i=q;i<q+min;i++){ 31 cout<<m[i]; 32 } 33 return 0; 34 }