[Pta]7-1 Find the smallest string for the input n string, output the smallest string (c + +)

Source: Internet
Author: User

7-1 find the smallest string the subject requires a program to output the smallest string for the input n strings.

Input format:

Enter the first line to give a positive integer n, followed by n lines, each row gives a non-empty string of less than 80 length, where no newline, space, tab characters appear.

Output format:

Output the smallest string in one line in the following format:

Min is: Minimum string input Sample:

5 Li Wang Zha Jin Xian Output Sample:

Min Is:jin

Answer:

1#include <iostream>2#include <string>3 using namespacestd;4 5 intMain ()6 { 7 intN;8 stringMin, K;9 TenCin>>N; OneCin>>K; Amin=K; -  -  for(intI=0; i<n-1; i++) the { -  -Cin>>K; -  + if(k<min) min=K; -  + } Acout<<"Min is:"<<Min<<Endl; at //System ("pause"); -}

Attach the commissioning process:

1#include <iostream>2#include <string>3 using namespacestd;4 5 intMain ()6 {7 intN;8 stringMax,min, K;9 TenCin>>N; One  Acout<<"Please enter"<<N<<"A string:"<<Endl; -  -Cin>>K; theMax =K; -min=K; -  -cout <<"K:"<<k<<Endl; +cout <<"Max:"<<Max<<Endl; -cout <<"Min:"<<Min<<Endl; +  A  for(intI=1; i<n;i++)  at { -cout<<"Please enter section"<<i+1<<"A string:"<<Endl; -Cin>>K; -  - if(K>max) max=K; -cout <<"Max:"<<Max<<Endl; in if(k<min) min=K; -cout <<"Min:"<<Min<<Endl; to  + } -cout<<"Max is:"<<Max<<Endl; thecout<<"Min is:"<<Min<<Endl; *  $System"Pause"); Panax Notoginseng  -}

Perhaps you have a better idea, welcome to communicate!

[Pta]7-1 Find the smallest string for the input n string, output the smallest string (c + +)

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.