Some items-enter three strings, output in order from small to large

Source: Internet
Author: User

Description

Enter three strings, which are output in order from small to large. Two sort functions are implemented using pointers and references, respectively. Enter and output data in the main function.

Input

3 Line string

Output is 3 rows from small to large. implemented by pointers. Output to 3 lines from small to large. Implemented by the reference method. Sample Input
Cdeafgabc
Sample Output
Abcafgcdeabcafgcde

Code

#include <iostream> #include <cstring>using namespace std;void sort1 (char *s1,char *s2,char *s3) {char t[100    ];        if (strcmp (S1,S2) >0) {strcpy (T,S1);        strcpy (S1,S2);    strcpy (s2,t);        } if (strcmp (S2,S3) >0) {strcpy (T,S3);        strcpy (S3,S2);    strcpy (s2,t);        } if (strcmp (S1,S2) >0) {strcpy (T,S1);        strcpy (S1,S2);    strcpy (s2,t);    }}void sort2 (String &s1,string &s2,string &s3) {string T;        if (S1&GT;S2) {t=s1;        S1=S2;    s2=t;        } if (S2&GT;S3) {t=s3;        S3=S2;    s2=t;        } if (S1&GT;S2) {t=s1;        S1=S2;    s2=t;    }}int Main () {void Sort1 (char *,char *,char *);    void Sort2 (String &,string &,string &);    Char s1[100],s2[100],s3[100];    Char *p1,*p2,*p3;    String R1,r2,r3;    cin>>s1>>s2>>s3;    R1=string (S1);    r2=string (S2);    R3=string (S3);    P1=S1;    P2=S2;    P3=S3; SorT1 (P1,P2,P3);    cout<<s1<<endl<<s2<<endl<<s3<<endl;    Sort2 (R1,R2,R3);    cout<<r1<<endl<<r2<<endl<<r3<<endl; return 0;}

Some items-enter three strings, output in order from small to large

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.