cout<<"int[] arr = new int[]{"; for (int i = 0; i <c; i++) { if (i) cout << ','; cout << arr[i]; } cout <<"};"<<endl; cout<<"int[] index = new int[]{"; for(int i=0;i<11;i++) { if(i)cout<<','; cout<< index[i]; } cout<<"};"; }
L1-027 出租
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int data[11],arr[11];
int index[11];
for(int i=0;i<11;i++)
{
scanf("%1d",&data[i]);
arr[i]=data[i];
}
sort(arr,arr+11);
reverse(arr,arr+11);
int c= unique(arr,arr+11)-arr;
for(int i=0;i<11;i++)
{
for (int j = 0; j < c; j++)
if(data[i]==arr[j]) index[i] =j;
}
cout<<"int[] arr = new int[]{"; for (int i = 0; i <c; i++) { if (i) cout << ','; cout << arr[i]; } cout <<"};"<<endl; cout<<"int[] index = new int[]{"; for(int i=0;i<11;i++) { if(i)cout<<','; cout<< index[i]; } cout<<"};"; }
cout<<"int[] arr = new int[]{"; for (int i = 0; i <c; i++) { if (i) cout << ','; cout << arr[i]; } cout <<"};"<<endl; cout<<"int[] index = new int[]{"; for(int i=0;i<11;i++) { if(i)cout<<','; cout<< index[i]; } cout<<"};"; }