Cards

来源:互联网 发布:淘宝手机助手ipad版 编辑:程序博客网 时间:2024/05/16 19:14

Description

There are 24 hours of train from Xuzhou to ChengDu.

You know, the time is too long. It's really important to find some fun. So we buy a deck of cards. After each one get its cards. It's better to sort these cards in no descending order. Often we move one card and insert it into somewhere.

Now I want to know the minimum move times to sort these cards.

Input

The first line is an integer T, indicates the number of test cases.

For each case, the first line is an integer N indicates the number of cards

Then the following line is the N cards number.

Output

For each case output the minimum times of move I need to do.

程序源代码:
#include<iostream>
using namespace std;
int main()
{
int T,N;
cin>>T;
for(int i=0;i<T;i++)
{
cin>>N;
int a[100];
int count=0;
int x=0;
for(int k=0;k<N;k++)
{
cin>>a[k];
}
for(int p=0;p<N;p++)
{
if(a[p]<a[p+1])
{
x=a[p];
a[p]=a[p+1];
a[p+1]=x;
count++;
}
else
{
continue;
}
}
cout<<count<<endl;
}
return 0;
}

运行结果:


希望各位大神指点。谢谢。

0 0