注意一下命名冲突的问题,index要么换名字要么写到局部变量。
#include <bits/stdc++.h>
using namespace std;
int arr[100],index2[100];
int main(){
string s,cy;
cin >> s;
cy =s;
sort(s.begin(),s.end(),greater<int>());
int ssize=unique(s.begin(),s.end())-s.begin();
for(int i=0;i<ssize;i++){
arr[i]=s[i]-'0';
}
for(int i=0;i<s.size();i++){
int pos = -1;
for(int j=0;j<ssize;j++){
if(arr[j]==cy[i]-'0'){
pos=j;
break;
}
}
index2[i]=pos;
}
/*
int[] arr = new int[]{8,3,2,1,0};
int[] index2 = new int[]{3,0,4,3,1,0,2,4,3,4,4};
*/
cout << "int[] arr = new int[]{";
for(int i=0;i<ssize;i++){
cout << arr[i];
if(i<ssize-1) cout << ",";
}
cout << "};" << endl;
cout << "int[] index = new int[]{";
//cout << s.size() << endl;
for(int i=0;i<s.size();i++){
cout << index2[i];
if(i<s.size()-1) cout << ",";
}
cout << "};";
return 0;
}
标签:begin,end,int,cy,027,出租,L1
From: https://www.cnblogs.com/chengyiyuki/p/18064428