Problem Type : Sorting
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
long int *a,n,i,j;
while(scanf("%ld",&n)==1)
{
if(n==0)
break;
a=(long int*)malloc(n*sizeof(long int));
for(i=0; i<n; i++)
{
scanf("%ld",a+i);
}
sort(a,a+n);
for(j=0; j<n-1; j++)
{
printf("%ld ",a[j]);
}
printf("%ld",a[j]);
printf("\n");
}
return 0;
}
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
long int *a,n,i,j;
while(scanf("%ld",&n)==1)
{
if(n==0)
break;
a=(long int*)malloc(n*sizeof(long int));
for(i=0; i<n; i++)
{
scanf("%ld",a+i);
}
sort(a,a+n);
for(j=0; j<n-1; j++)
{
printf("%ld ",a[j]);
}
printf("%ld",a[j]);
printf("\n");
}
return 0;
}
No comments:
Post a Comment