996D Codeforces - Suit and Tie


99D Codeforces - Suit and Tie


Solution in c++

#include <iostream>

using namespace std;

int main()
{
    int n,sol=0;
    cin>>n;
    int nn[2*n];
    for(int i=0;i<2*n;i++){
        cin>>nn[i];
    }
    for(int i=0;i<2*n;i+=2){
            int pos;
        
        for(int k=2*n-1;k>i;k--){if(nn[k]==nn[i]){pos=k;}}
        while(pos>i+1){
            swap(nn[pos],nn[pos-1]);
            pos--;
            sol++;
        }

    }
    cout<<sol;
    return 0;
}
Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق