2 solutions
-
0
#include<bits/stdc++.h> typedef long long LL; using namespace std; const int N = 1e3 + 10; int a[N],cnt,n; int main() { cin >> n; for(int i = 1;i <= n;++ i) { cin >> a[i]; } //冒泡排序部分: for(int i = 1;i < n;++ i) { for(int j = 1;j <= n - i;++ j) { if(a[j] > a[j + 1]) { int tmp = a[j]; a[j] = a[j + 1]; a[j + 1] = tmp;//交换 cnt ++;//计数 } } } // for(int i = 1;i <= n;++ i) // { // cout << a[i] << " "; // } cout << cnt; return 0; }
- 1
Information
- ID
- 6823
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- # Submissions
- 294
- Accepted
- 65
- Uploaded By