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