Cod sursa(job #2753774)

Utilizator bogdan2405Strat Bogdan-Valentin bogdan2405 Data 24 mai 2021 13:00:07
Problema Schi Scor 65
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.13 kb
//#include<bits/stdc++.h>
#include<iostream>
#include<fstream>
#include<vector>

using namespace std;

ifstream f("schi.in");
ofstream g("schi.out");

int main(){
    int i,n,pozitie,j,k;
    f>>n;
    vector<pair<int,int>> v;
    pair<int,int> pereche;
    pair<int,int> aux;
    for(i=1;i<=n;++i){
        f>>pozitie;
       
        pereche=make_pair(pozitie,i);
        if(pozitie==i){
            v.push_back(pereche);
        }
        else{
            //v.push_back(pereche);
            for(j=0;j<v.size();++j){
                if(v[j].first==pozitie){
                    v.insert(v.begin()+j,pereche);
                    /*for(k=v.size()-2;k>=j;k--){
                        v[k].first=v[k].first+1;
                        aux=v[k+1];
                        v[k+1]=v[k];
                        v[k]=aux;
                    }*/
                    for(k=j+1;k<v.size();++k){
                        v[k].first=v[k].first+1;
                    }
                    break;
                    //v[j]=pair;
                }
        }
        }
        
    }
    
    for(i=0;i<v.size();++i){
        g<<v[i].second<<'\n';
    }
    return 0;
}