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;
}
运行结果:
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
- Cards
- Cards
- Cards
- Cards
- 接着cards
- 15、Cards
- CARDS----置换
- poj_1511Invitation Cards
- 4610 Cards
- Invitation Cards
- Move cards
- Christmas Cards
- Invitation Cards
- [HNOI2008]Cards
- BZOJ_1004 Cards
- Invitation Cards
- 【BZOJ1004】Cards
- poj1511Invitation Cards
- .zip和.tar.gz的文件有什么区别?
- 第三天
- Codeforces 723B Text Document Analysis
- 初识 gradle
- 别轻易自责,专注力和自制力是稀缺资源
- Cards
- CNKI PDF全文下载脚本
- win10更新后ChsIME CPU使用率高
- Codeforces Round #375 (Div. 2) B
- 已有Android,谷歌又开发新系统Fuchsia,意欲何为
- Medium 200题 Number of Islands
- 自动提示宏--输入什么属性,就把属性自动生成OC字符串
- 【管理者】精读德鲁克教授《卓有成效的管理者》<一>
- nginx是以多进程的方式来工作的