Ytu 2419:c language exercises and other long string sorting

Source: Internet
Author: User
Tags time limit
2419:c language exercises and other long string sortingTime limit:1 Sec Memory limit:128 MB
submit:426 solved:169
[Submit] [Status] [Web Board] Description

Enter an equal-length string of n (n<=10) in the main function. Sort them with another function. It then outputs the n sorted string in the main function. Input

N and N equal-length string Output

n a sorted string, Sample Input ,

5
abcdf
12345
ert45
fg432
erfff
Sample Output
12345
abcdf
erfff
ert45

fg432

AC Code:

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cstring>
using namespace std;
void sort (char s[10][80],int N) {
    char *p,temp[10];
    int i,j;
    P=temp;
    For (i=0 i<n; i++) for
        (j=0; j<n-i-1; j + +)
            if (strcmp (s[j],s[j+1)) >0) {
                strcpy (p,s[j
                )); strcpy (s[j],s[j+1]);
                strcpy (s[j+1],p);
            }
int main ()
{
    void sort (char [][80],int);
    int i;
    Char str[10][80];
    int n;
    cin>>n;
    For (i=0 i<n; i++)
        cin>>str[i];
    Sort (str,n);
    For (i=0 i<n; i++)
        cout<<str[i]<<endl;
    return 0;
}



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.