int[] a = new int[]{5,7,9,-6,0,77,900,6}; int[] b = new int[]{5,7,9,-6,0,77,900,6}; Arrays.sort(b); for(int i=0; i<a.length; i++) { while(a[i] != b[j++]) { } System.out.print(j + "\t"); } 伪代码咯,呵呵
int[] a = new int[]{5,7,9,-6,0,77,900,6}; int[] b = new int[]{5,7,9,-6,0,77,900,6}; java.util.Arrays.sort(b); for(int i=0; i<a.length; i++) { int j=0; while(a[i] != b[j]) { j++; } System.out.print(j + "\t"); }大意了,更正一下,(~ o ~)~zZ
int[] b = new int[]{5,7,9,-6,0,77,900,6};
Arrays.sort(b);
for(int i=0; i<a.length; i++) {
while(a[i] != b[j++]) {
}
System.out.print(j + "\t");
}
伪代码咯,呵呵
int[] a = new int[]{5,7,9,-6,0,77,900,6};
int[] b = new int[]{5,7,9,-6,0,77,900,6};
java.util.Arrays.sort(b);
for(int i=0; i<a.length; i++) {
int j=0;
while(a[i] != b[j]) {
j++;
}
System.out.print(j + "\t");
}大意了,更正一下,(~ o ~)~zZ
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int array[] = {5, 7, 9, -6, 0, 77, 900, 6};
size_t array_size = sizeof(array)/sizeof(int);
vector<int> ivec(array, array + array_size);
sort(ivec.begin(), ivec.end());
for(int i=0; i<array_size; ++i){
cout<<(find(ivec.begin(), ivec.end(), array[i]) - ivec.begin())<<" ";
}
cout<<endl;
return 0;
}