大佬快来帮帮我!!!!!!!!!
2023-09-30 20:11:13
发布于:河南
题目描述
小码君给了你 n 个整数,你需要将这些数字按照个位数的大小从大到小进行排序,如果个位数一样则按照数字从小到大的顺序排序。
输入格式
第一行一个整数 n(1≤n≤1e5),表示整数的个数。
接下来一行 n 个整数,每个整数都在 int 范围内。
输出格式
输出 n 行,每行一个整数。
样例组输入#1
3
1
22
31
样例组输出#1
22
1
31
这道题怎么写呀,有没有人帮帮我!求求了!!!
全部评论 2
std::sort写个 vector 然后写个 cmp 匿名函数输出就可以了
2023-09-30 来自 四川
1#include<bits/stdc++.h>
using namespace std;
struct q{
int w[10008];
}a[10008];
bool cmp(q x,q y){
return x.w>y.w;
}
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){2023-10-01 来自 河南
0cin>>a[i].w;
}
sort (a,a+n,cmp);
for(int i=0;i<n;i++){
cout<<a[i].w<< " " ;
}
return 0;
}2023-10-01 来自 河南
0可以帮我改一下吗?
2023-10-01 来自 河南
0
std::sort会吧,普通快排和归并排会吧
2023-09-30 来自 四川
0
有帮助,赞一个