Pagini recente » Cod sursa (job #2109900) | Cod sursa (job #2920350) | Cod sursa (job #451675) | Cod sursa (job #1961934) | Cod sursa (job #1482419)
#include<fstream>
#define nmax 500001
using namespace std;
int v[nmax],w[nmax];
void Ordoneaza(int s,int d)
{
if(d-s==1) return ;
int i=s,m=(s+d)>>1,j=m,k=s;
Ordoneaza(s,m);
Ordoneaza(m,d);
while(i<m || j<d)
if(j>=d || (i<m && v[i]<v[j]))
w[k++]=v[i++];
else w[k++]=v[j++];
for(k=s;k<d;++k)
v[k]=w[k];
}
int main()
{
ifstream f("algsort.in");
ofstream g("algsort.out");
int n,i;
bool sortd=true;
f>>n>>v[0];
for(i=1;i<n;++i){
f>>v[i];
sortd=sortd&&(v[i]>=v[i-1]);
}
if(!sortd) Ordoneaza(0,n);
for(i=0;i<n;++i)
g<<v[i]<<" ";
g<<"\n";
f.close();
g.close();
return 0;
}
/*
#include<fstream>
#include<cstdlib>
#include<ctime>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
int x = 0;
// it's about the expression which continas ++x or x++ market by ( ), not about the statement
printf("1. %d\n", (++x + ++x + ++x));
x = 0;
printf("2. %d\n", (x++ + x++ + x++));
printf("3. %d\n", x);
x = 0;
printf("4. %d\n", ((++x) + (++x) + (++x)));
x = 0;
printf("5. %d\n", ((x++) + (x++) + (x++)));
printf("6. %d\n", x);
x = 0;
printf("7. %d\n", ((x += 1) + (x += 1) + (x += 1)));
x = 0;
printf("8. %d\n", ((x += 1) + (x += 2) + (x += 3)));
x = 0;
printf("9. %d\n", ((x += 3) + (x += 2) + (x += 1)));
x = 0;
return 1;
ofstream fout("out.txt");
int st,st2,nr,i,j;
cin>>st>>st2>>nr;
fout<<"1-"<<st<<","<<st2<<",";
/// working on the assumption that st2-st>nr-st2
++st2;
++st;
i=((st2-2)-st+1)/(nr-st2+1)+1;
for(;st2<=nr && st<st2;++st2,st+=i+1)
fout<<st<<"-"<<st+i<<","<<st2<<",";
if(st2<=nr) fout<<st2<<"-"<<nr;
fout.close();
return 0;
}
*/