L1-027 出租
题目 L1-027 出租
思路分析
代码实现
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
using ll = long long;
using ull = unsigned long long;
using PII = pair<int,int>;
using Pll = pair<ll,ll>;
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
const int inf=0x3f3f3f3f;
const int N=20;
vector<int> arr,idx;
set<int> contains;
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
//给定字符串中有哪些数字 降序输出
//记录每个原位置的数在新降序数组中的位置
// 要维护 原位置 以及排序后的位置 用到pair 不是很好搞
// 干脆打暴力 对每个数去找新位置
string s;cin>>s;
for(auto c:s) contains.insert(c-'0');
for(auto n:contains) arr.push_back(n);
reverse(arr.begin(),arr.end());
cout<<"int[] arr = new int[]{";
for(int i=0;i<arr.size();i++) {
cout<<arr[i];
if(i!=arr.size()-1) cout<<",";
}
cout<<"};";
cout<<endl;
cout<<"int[] index = new int[]{";
for(int i=0;i<s.size();i++){
for(int j=0;j<arr.size();j++){
if(s[i]-'0'==arr[j]){
cout<<j;
break;
}
}
if(i!=s.size()-1) cout<<",";
}
cout<<"};";
return 0;
}
同类题型
视频讲解
⬅️ L1-026 I Love GPLT 🏠 00-天梯赛 ➡️ L1-028 判断素数
💬 评论