cxf2012 @ 2024-08-31 16:33:17
#include<bits/stdc++.h>
using namespace std;
long long n,y[101],m[101],d[101];
string s[101];
int main() {
ios::sync_with_stdio(0);
freopen("P1104_6.in","r",stdin);
freopen("P1104_6.out","w",stdout);
cin>>n;
for(int i=1; i<=n; i++) {
cin>>s[i]>>y[i]>>m[i]>>d[i];
}
for(int i=1; i<=n; i++) {
for(int j=i+1; j<=n; j++) {
if(y[i]>y[j]) {
swap(y[i],y[j]);
swap(s[i],s[j]);
swap(m[i],m[j]);
swap(d[i],d[j]);
}
if(y[i]==y[j]) {
if(m[i]>m[j]) {
swap(y[i],y[j]);
swap(s[i],s[j]);
swap(m[i],m[j]);
swap(d[i],d[j]);
}
if(m[i]==m[j]) {
if(d[i]>d[j]) {
swap(y[i],y[j]);
swap(s[i],s[j]);
swap(m[i],m[j]);
swap(d[i],d[j]);
}
}
}
}
}
for(int i=1;i<=n;i++)
cout<<s[i]<<endl;
return 0;
}
QAQ
by CQ天神 @ 2024-08-31 16:35:18
@cxf2012 写个sort+cmp不好吗
by lxr_Galaxy @ 2024-08-31 16:35:47
试用一下结构体吧,感觉代码不复杂但是好长QAQ @cxf2012
by Yxy7952 @ 2024-08-31 16:35:56
@CQ天神
啊对对对
by cxf2012 @ 2024-08-31 16:36:22
@lxr_Galaxy 好吧
by lxr_Galaxy @ 2024-08-31 16:36:30
@CQ天神 他没用结构体,不用用sort+cmp(应该吧)
by lzh_juruo @ 2024-08-31 16:37:17
@cxf2012
by CQ天神 @ 2024-08-31 16:37:50
@lxr_Galaxy 但是很复杂,如果在比赛中这样写,我觉得T3都做不完
by Yxy7952 @ 2024-08-31 16:38:55
@cxf2012
仅作参考
#include<bits/stdc++.h>
using namespace std;
struct abc{
string s;
int y,m,d,id;
};
abc a[105];
int n;
bool c(abc i,abc k){
if(i.y==k.y){
if(i.m==k.m){
if(i.d==k.d){
return i.id>k.id;
}
return i.d<k.d;
}
return i.m<k.m;
}
return i.y<k.y;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].s;
cin>>a[i].y;
cin>>a[i].m;
cin>>a[i].d;
a[i].id=i;
}
sort(a+1,a+n+1,c);
for(int i=1;i<=n;i++){
cout<<a[i].s<<endl;
}
return 0;
}
by cxf2012 @ 2024-08-31 16:41:52
#include<bits/stdc++.h>
using namespace std;
long long n,y[101],m[101],d[101];
string s[101];
int main() {
ios::sync_with_stdio(0);
//freopen("P1104_6.in","r",stdin);
//freopen("P1104_6.out","w",stdout);
cin>>n;
for(int i=1; i<=n; i++) {
cin>>s[i]>>y[i]>>m[i]>>d[i];
}
for(int i=1; i<=n; i++) {
for(int j=i+1; j<=n; j++) {
if(y[i]>y[j]) {
swap(y[i],y[j]);
swap(s[i],s[j]);
swap(m[i],m[j]);
swap(d[i],d[j]);
}
if(y[i]==y[j]) {
if(m[i]>m[j]) {
swap(y[i],y[j]);
swap(s[i],s[j]);
swap(m[i],m[j]);
swap(d[i],d[j]);
}
if(m[i]==m[j]) {
if(d[i]>d[j]) {
swap(y[i],y[j]);
swap(s[i],s[j]);
swap(m[i],m[j]);
swap(d[i],d[j]);
}
if(d[i]==d[j]) {
if(i<j) {
swap(y[i],y[j]);
swap(s[i],s[j]);
swap(m[i],m[j]);
swap(d[i],d[j]);
}
}
}
}
}
}
for(int i=1; i<=n; i++)
cout<<s[i]<<endl;
return 0;
}
本人已AC
by lxr_Galaxy @ 2024-08-31 21:30:56
@CQ天神 认同,但这题还行,不用思考太多,数组开大了也不会MLE,用不用应该都无所谓吧