SnowZ @ 2024-10-18 20:48:53
#include<stdio.h>
#include<stdlib.h>
struct Person
{
char name[21];
int year;
int month;
int day;
};
void sort(struct Person arr[], int n){
for(int i = 0; i < n - 1; i++){
for(int j = 0; j < n - i - 1; j++){
if((arr[j].year > arr[j+1].year) ||
((arr[j].year == arr[j+1].year) && arr[j].month > arr[j+1].month) ||
((arr[j].year == arr[j+1].year) && (arr[j].month == arr[j+1].month) && arr[j].day >= arr[j+1].day)){
struct Person temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
int main()
{
int n;
scanf("%d",&n);
struct Person p[101];
for(int i = 0; i < n; i++){
scanf("%s %d %d %d",p[i].name,&p[i].year,&p[i].month,&p[i].day);
}
sort(p, n);
for(int i = 0; i < n; i++){
printf("%s\n",p[i].name);
}
return 0;
}
by Czero_2023 @ 2024-10-18 20:56:13
@SnowZ 输入靠后的人先输出?
by xywuyu @ 2024-10-18 20:56:36
#include<bits/stdc++.h>
using namespace std;
struct stu{
int a;
int b;
int c;
long long d;
string t;
}a[1000];
long long e[1000];
int main()
{int n;
cin>>n;
for (int i=1;i<=n;i++)
{
cin>>a[i].t>>a[i].a>>a[i].b>>a[i].c;
e[i]=a[i].a*800+a[i].b*50+a[i].c;
a[i].d=e[i];}
sort(e+1,e+n+1);
for (int i=1;i<=n;i++)
{if (e[i]==e[i+ 1])
continue;
for (int j=n;j>=1;j--)
{if (e[i]==a[j].d)
cout<<a[j].t<<"\n";
}
}
return 0;}
by SnowZ @ 2024-10-18 21:15:04
#include<stdio.h>
#include<stdlib.h>
struct Person
{
char name[21];
int year;
int month;
int day;
};
void sort(struct Person arr[], int n){
for(int i = 0; i < n - 1; i++){
for(int j = 0; j < n - i - 1; j++){
if((arr[j].year > arr[j+1].year) ||
((arr[j].year == arr[j+1].year) && (arr[j].month > arr[j+1].month)) ||
((arr[j].year == arr[j+1].year) && (arr[j].month == arr[j+1].month) && (arr[j].day > arr[j+1].day)) ||
((arr[j].year == arr[j+1].year) && (arr[j].month == arr[j+1].month) && (arr[j].day == arr[j+1].day))){
struct Person temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
int main()
{
int n;
scanf("%d",&n);
struct Person p[101];
for(int i = 0; i < n; i++){
scanf("%s %d %d %d",p[i].name,&p[i].year,&p[i].month,&p[i].day);
}
sort(p, n);
for(int i = 0; i < n; i++){
printf("%s\n",p[i].name);
}
return 0;
}
@Czero_2023 我加了全等也不对啊