LightOJ 1166 Old Sorting Solution




 Problem Link:https://lightoj.com/problem/old-sorting

Solve in C++:

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,t,i,ans,j,k;
    cin>>t;
    for(k=1; k<=t; k++)
    {
        cin>>n;
        long long  int a[n+9];
        ans=0;
        for(i=1; i<=n; i++)
            cin>>a[i];

        for(i=1; i<=n; i++)
        {
            if(a[i]!=i)
            {
                for(j=i+1; j<=n; j++)
                {
                    if(a[j]==i)
                    {
                        swap(a[i],a[j]);
                        ans++;
                        break;
                    }

                }
            }
        }
        cout<<"Case "<<k<<": "<<ans<< endl;
    }
}





No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.