OJ "input three strings, output in order from small to large"

Source: Internet
Author: User

Title 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

The output is output to 3 lines 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
Tips

The main function is given below, and it is not required to include the following main function when committing

/* C + + code */
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;
}

The code is as follows:

#include <iostream> #include <cstring>using namespace std;void sort1 (char *p1,char *p2,char *p3) {char temp[    100];        if (strcmp (P1,P2) >0) {strcpy (TEMP,P1);        strcpy (P1,P2);    strcpy (p2,temp);        } if (strcmp (P2,P3) >0) {strcpy (TEMP,P2);        strcpy (P2,P3);    strcpy (p3,temp);        } if (strcmp (P1,P2) >0) {strcpy (TEMP,P1);        strcpy (P1,P2);    strcpy (p2,temp);    }}void sort2 (String &r1,string &r2,string &r3) {string temp;        if (R1&GT;R2) {temp=r1;        R1=R2;    R2=temp;        } if (R2&GT;R3) {temp=r2;        R2=R3;    R3=temp;        } if (R1&GT;R2) {temp=r1;        R1=R2;    R2=temp;    }}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;}


I really feel silly about pointers and references ... All kinds of change, finally changed out, and to judge multiple string size comparisons need to pay attention to the order. Once wrong answer in exchange for the lesson, this judgment of the order is not the same as the previous one, and then the wrong ... Had to change back.

OJ "input 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.