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;
}