3578:车厢重组

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n, a[10005], ct = 0;//ct:数据交换的次数 
	cin >> n;
	for(int i = 1; i <= n; ++i)
		cin >> a[i];
	for(int i = 1; i <= n-1; ++i)
		for(int j = 1; j <= n-i; ++j)
			if(a[j] > a[j+1])
			{
				swap(a[j], a[j+1]);
				ct++;
			}
	cout << ct;
	return 0; 
}
相关推荐
小白菜又菜1 天前
Leetcode 3432. Count Partitions with Even Sum Difference
算法·leetcode
wuhen_n1 天前
LeetCode -- 15. 三数之和(中等)
前端·javascript·算法·leetcode
sin_hielo1 天前
leetcode 2483
数据结构·算法·leetcode
Xの哲學1 天前
Linux多级时间轮:高精度定时器的艺术与科学
linux·服务器·网络·算法·边缘计算
大头流矢1 天前
归并排序与计数排序详解
数据结构·算法·排序算法
阿闽ooo1 天前
外观模式:从家庭电源控制看“简化接口“的设计智慧
c++·设计模式·外观模式
油泼辣子多加1 天前
【信创】算法开发适配
人工智能·深度学习·算法·机器学习
一路往蓝-Anbo1 天前
【第20期】延时的艺术:HAL_Delay vs vTaskDelay
c语言·数据结构·stm32·单片机·嵌入式硬件
Aaron15881 天前
AD9084和Versal RF系列具体应用案例对比分析
嵌入式硬件·算法·fpga开发·硬件架构·硬件工程·信号处理·基带工程
laocooon5238578861 天前
插入法排序 python
开发语言·python·算法