- 冒泡排序交换次数
T1010不知道错哪了,求解
- 2023-12-21 18:49:40 @
#include<bits/stc++.h>
using namespace std;
int a[3000];
int main()
{ int n,cnt;
cin>>n;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)
for(int j=1; j<n;j++)
{
if(a[i]>a[j])
{
swap(a[i],a[j]) ;
cnt++; } }
cout<<cnt;
return 0;
}
1 comments
-
进击的卡勒 LV 8 @ 2023-12-21 19:16:25
cnt要 int cnt= 0; 不然就是随机数
- 1
Information
- ID
- 689
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- # Submissions
- 114
- Accepted
- 35
- Uploaded By