|

楼主 |
发表于 2024-6-30 20:32:43
|
显示全部楼层
我的代码:
- #include <iostream>
- #include <algorithm>
- using namespace std;
- struct student{
- int dao, lg, zi;
- char str[1002];
- }stu[10002];
- bool cmp(student a, student b){
- if (a.dao != b.dao) return a.dao > b.dao;
- else if (a.lg != b.lg) return a.lg < b.lg;
- else{
- for (int i = 0; i <= 1000; i++){
- if (a.str[i] != b.str[i]) return a.str[i] < b.str[i];
- }
- }
- }
- void qs(int q){
- for (int i = 1; i <= q; i++){
- cin >> stu[i].str;
- stu[i].dao = 0;
- stu[i].lg = 0;
- stu[i].zi = 0;
- int temp = 0;
- while (stu[i].str[stu[i].lg]){
- if (stu[i].str[stu[i].lg] == '7'){
- stu[i].dao++;
- }
- stu[i].lg++;
- }
- }
- sort(stu + 1, stu + q + 1, cmp);
- for (int i = 1; i <= q; i++){
- cout << stu[i].str << endl;
- }
- }
- int main(){
- int n;
- cin >> n;
- qs(n);
- }
复制代码
@Fishc |
|