[PTA] 7-1 find the smallest string for the input N strings, output the smallest string (c ++), pta7-1

Source: Internet
Author: User

[PTA] 7-1 find the smallest string for the input N strings, output the smallest string (c ++), pta7-1

7-1 find the smallest string this question requires programming, for the input N strings, output the smallest string.

Input Format:

The first line of the input is a positive integer N, followed by N rows. Each line is a non-null string of less than 80 characters, without line breaks, spaces, and tabs.

Output Format:

Output the smallest string in the following format in a row:

Min is: Minimum string input example:

5 Li Wang Zha Jin Xian output example:

Min is: Jin

Answer:

 1 #include <iostream> 2 #include<string>  3 using namespace std; 4  5 int main() 6 {  7 int N; 8 string Min, k; 9 10 cin>>N;11 cin>>k;12 Min=k;13 14 for(int i=0;i<N-1;i++)15 {16 17 cin>>k;18 19 if(k<Min) Min=k;20 21 }22 cout<<"Min is: "<<Min<<endl;23 //system("pause"); 24 }

 

Attached debugging process:

1 # include <iostream> 2 # include <string> 3 using namespace std; 4 5 int main () 6 {7 int N; 8 string Max, Min, k; 9 10 cin> N; 11 12 cout <"enter" <N <"strings:" <endl; 13 14 cin> k; 15 Max = k; 16 Min = k; 17 18 cout <"k:" <k <endl; 19 cout <"Max: "<Max <endl; 20 cout <" Min: "<Min <endl; 21 22 for (int I = 1; I <N; I ++) 23 {24 cout <"Enter the" <I + 1 <"string:" <endl; 25 cin> k; 26 27 if (k> Max) Max = k; 28 cout <"Max:" <Max <endl; 29 if (k <Min) Min = k; 30 cout <"Min:" <Min <endl; 31 32} 33 cout <"Max is:" <Max <endl; 34 cout <"Min is:" <Min <endl; 35 36 system ("pause"); 37 38}

Maybe you have a better idea. Please contact us!

Related Article

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.