প্রবলেমটি পড়ুন এবং বুঝুন
#include<iostream>
using namespace std;
int main()
{
long int test,n;
cin>>test;
while(test--)
{
cin>>n;
int a[n],counter=0;
for(int i=0; i<n; i++)
{
cin>>a[i];
for(int k=0; k<i; k++)
{
if(a[i]<a[k])
{
int t=a[k];
a[k]=a[i];
a[i]=t;
counter++;
}
}
}
cout<<"Optimal train swapping takes "<<counter<<" swaps."<<endl;
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
long int test,n;
cin>>test;
while(test--)
{
cin>>n;
int a[n],counter=0;
for(int i=0; i<n; i++)
{
cin>>a[i];
for(int k=0; k<i; k++)
{
if(a[i]<a[k])
{
int t=a[k];
a[k]=a[i];
a[i]=t;
counter++;
}
}
}
cout<<"Optimal train swapping takes "<<counter<<" swaps."<<endl;
}
return 0;
}
No comments:
Post a Comment