Cod sursa(job #1019719)

Utilizator AlexandravVoda Alexandra Ioana Alexandrav Data 31 octombrie 2013 20:34:44
Problema Statistici de ordine Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 1.02 kb
#include<iostream>
#include<fstream>
using namespace std;
int n, x[100];

void interclasare(int s,int d)
{
    int y[100], mij, c=0, i, j;
    mij=(s+d)/2;
    i=s;
    j=mij+1;
    while(i<=mij && j<=d)
    {
        if(x[i]<x[j])
        {
            c++;
            y[c]=x[i];
            i++;
        }
        else
        {
            c++;
            y[c]=x[j];
            j++;
        }
    }
    while(i<=mij)
    {
        c++;
        y[c]=x[i];
        i++;
    }
    while(j<=d)
    {
        c++;
        y[c]=x[j];
        j++;
    }
    c=0;
    for(i=s;i<=d;i++)
    {
        c++;
        x[i]=y[c];
    }
}
void mergesort(int s,int d)
{
    int m;
    if(s<d)
    {
        m=(s+d)/2;
        mergesort(s,m);
        mergesort(m+1,d);
        interclasare(s,d);
    }
}
int main()
{
    int i,k;
    ifstream f("sdo.in");
    ofstream g("sdo.out");
    f>>n>>k;
    for( i=1;i<=n;i++)
        f>>x[i];
    mergesort(1,n);
    g<<x[k];
    return 0;
}