LMR_Minecraft @ 2024-11-08 12:24:53
#include<iostream>
using namespace std;
int n;
int a[100], b[100], c[100], x[100];
string s[100], temp;
int main() {
cin >> n;
for (int i = 0; i < n; i++)cin >> s[i] >> a[i] >> b[i] >> c[i];
for (int i = 0; i < n; i++) {
for (int j = 1; j < n; j++) {
if (a[i] > a[j]) {
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
else if (a[i] == a[j]) {
if (b[i] > b[j]) {
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
else if (b[i] == b[j]) {
if (c[i] > c[j]) {
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
}
}
}
for (int i = 0; i < n; i++)cout << s[i] << endl;
}
by WangSiHan_2011 @ 2024-11-08 12:35:53
如果有两个同学生日相同,输入靠后的同学先输出
by WangSiHan_2011 @ 2024-11-08 12:36:14
然后建议你学一下swap函数
by WangSiHan_2011 @ 2024-11-08 12:37:06
#include<iostream>
using namespace std;
int n;
int a[100], b[100], c[100], x[100];
string s[100], temp;
int main() {
cin >> n;
for (int i = 0; i < n; i++)cin >> s[i] >> a[i] >> b[i] >> c[i];
for (int i = 0; i < n; i++) {
for (int j = 1; j < n; j++) {
if (a[i] > a[j]) {
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
else if (a[i] == a[j]) {
if (b[i] > b[j]) {
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
else if (b[i] == b[j]) {
if (c[i] >= c[j]) {
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
}
}
}
for (int i = 0; i < n; i++)cout << s[i] << endl;
}
by LMR_Minecraft @ 2024-11-08 12:37:15
swap我会
by WangSiHan_2011 @ 2024-11-08 12:37:39
然后建议你加一下 return 0;
by LMR_Minecraft @ 2024-11-08 12:38:10
@WangSiHan_2011 谢谢了,我会用swap,已发现错误,谢了
by LMR_Minecraft @ 2024-11-08 12:40:09
@WangSiHan_2011 新程序(最后一个样例没过)
#include<iostream>
using namespace std;
int n;
int a[100], b[100], c[100], x[100];
string s[100], temp;
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> s[i] >> a[i] >> b[i] >> c[i];
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
swap(s[i], s[j]);
swap(a[i], a[j]);
swap(b[i], b[j]);
swap(c[i], c[j]);
}
else if (a[i] == a[j]) {
if (b[i] > b[j]) {
swap(s[i], s[j]);
swap(a[i], a[j]);
swap(b[i], b[j]);
swap(c[i], c[j]);
}
else if (b[i] == b[j]) {
if (c[i] > c[j]) {
swap(s[i], s[j]);
swap(a[i], a[j]);
swap(b[i], b[j]);
swap(c[i], c[j]);
}
}
}
}
}
for (int i = 0; i < n; i++) cout << s[i] << endl;
}
by LMR_Minecraft @ 2024-11-08 12:40:49
@WangSiHan_2011 这啥