逆序数问题C++多种方法实现
作者:互联网
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;
int main(){
//day:5/29
//question:逆序数问题
//input: 9 2 7 4 -1
//output:(9,2),(9,7),(9,4),(9,-1),(2,-1),(7,4),(7,-1),(4,-1)
//方法一:暴力枚举法
vector<int> v={9,2,7,4,-1};
int ans=0;
for(int i=0;i<v.size();i++){
for(int j=i+1;j<v.size();j++){
if(v[i]>v[j]){
ans++;
cout<<"("<<v[i]<<","<<v[j]<<")"<<endl;
}
}
}
cout<<ans;
system("pause");
return 0;
}
标签:多种,枚举法,int,namespace,C++,ans,include,序数 来源: https://blog.csdn.net/qq_44833392/article/details/117386371