Pagini recente » Cod sursa (job #307727) | Cod sursa (job #936489) | Cod sursa (job #310432) | Cod sursa (job #265547) | Cod sursa (job #1885968)
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
/**
`-.`'.-'
`-. .-'.
`-. -./\.- .-'
-. /_|\ .-
`-. `/____\' .-'.
`-. -./.-""-.\.- '
`-. /< (()) >\ .-'
- .`/__`-..-'__\' .-
,...`-./___|____|___\.-'.,.
,-' ,` . . ', `-,
,-' ________________ `-,
,'/____|_____|_____\
/ /__|_____|_____|___\
/ /|_____|_____|_____|_\
' /____|_____|_____|_____\
.' /__|_____|_____|_____|___\
,' /|_____|_____|_____|_____|_\
,,---''--...___...--'''--.. /../____|_____|_____|_____|_____\ ..--```--...___...--``---,,
'../__|_____|_____|_____|_____|___\
\ ) '.:/|_____|_____|_____|_____|_____|_\ ( /
)\ / ) ,':./____|_____|_____|_____|_____|_____\ ( \ /(
/ / ( ( /:../__|_____|_____|_____|_____|_____|___\ ) ) \ \
| | \ \ /.../|_____|_____|_____|_____|_____|_____|_\ / / | |
.-.\ \ \ \ '..:/____|_____|_____|_____|_____|_____|_____\ / / / /.-.
(= )\ `._.' | \:./ _ _ ___ ____ ____ _ _ _ _ _ _ _ __\ | `._.' /( =)
\ (_) ) \/ \ ( (_) /
\ `----' """""""""""""""""""""""""""""""""""""""""""""" `----' /
\ ____\__ __/____ /
\ (=\ \ / /-) /
\_)_\ \ / /_(_/
\ \ / /
) ) _ _ ( (
( (,-' `-..__ __..-' `-,) )
\_.-'' ``-..____ ____..-'' ``-._/
`-._ ``--...____...--'' _.-'
`-.._ _..-'
`-..__ CIOBY KNOWS ALL __..-'
``-..____ ____..-''
``--...____...--''
*/
class parser{
public:
parser() {}/// use file.close()?
parser(const char *file_name){
input_file.open(file_name,ios::in | ios::binary);
input_file.sync_with_stdio(false);
index=0;
input_file.read(buffer,SIZE);}///input iterators?
inline parser &operator >>(int &n){
for (;buffer[index]<'0' or buffer[index]>'9';inc());
n=0;
for (;'0'<=buffer[index] and buffer[index]<='9';inc())
n=10*n+buffer[index]-'0';
return *this;}
private:
fstream input_file;
static const int SIZE=0x8000;///512kb file buffer?
char buffer[SIZE];
int index=0;
inline void inc(){
if(++index==SIZE)
index=0,input_file.read(buffer,SIZE);}
};
ifstream f ("algsort.in");
ofstream t ("algsort.out");
vector <int> v;
int n;
int partition(int low,int high)
{ int mid=(low+high)/2;
int pivot=v[mid];
int i=low-1;
int j=high+1;
LOOP:
do
++i;
while (v[i]<pivot);
do
--j;
while (v[j]>pivot);
if (i>=j)
return j;
swap(v[i],v[j]);
goto LOOP;
}
void quicksort(int low,int high)
{
int pivot;
if (low<high)
{
pivot=partition(low,high);
quicksort(low,pivot);
quicksort(pivot+1,high);
}
}
void citire()
{
f>>n;
v.resize(n);///push_back faster?
for (int i=0; i<n; ++i)
f>>v[i];
}
inline void afisare()
{
for (int i=0; i<n; ++i)
t<<v[i]<<" ";
}
int main()
{
citire();
quicksort(0,n-1);
afisare();
return 0;
}