找朋友(插入排序青春版)[(https://www.online1987.com/找朋友/)]
#include<iostream>
#include<vector>
using namespace std;
int main() {
int N = 0;
cin >> N;
vector<int> res;
vector<int> height(N, 0);
for (int i = 0; i < N; ++i) {
cin >> height[i];
}
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j<N;++j) {
if (height[i] < height[j]) {
cout << j << endl;
break;
}
else if(j==N-1)
cout << 0 << endl;//没找到返回0;
}
}//相比于插入排序少了一个交换的步骤。
cout << 0 << endl;
return 0;
}
标签:朋友,++,插入排序,cin,height,青春,int,vector
From: https://www.cnblogs.com/chunbai11/p/16744654.html