状态:Compile Error
估计是strcpy使用使得编译错误,本人用的vs2022关闭了SDL编译成功了,所以我们可以编写一个函数代替strcpy,本人太懒就没写(滑稽)
#include<iostream>
#include<string>
using namespace std;
class information
{
private:
char name[20];
int score;
public:
void get()
{
cin >> name >> score;
}
void show()
{
cout << name << " " << score << endl;
}
int Score()
{
int a;
a = score;
return a;
}
char Name()
{
char a;
a = name[0];
return a;
}
friend void exchange(information& a, information& b)
{
information s;
s.score = a.score;
strcpy(s.name, a.name);
a.score = b.score;
strcpy(a.name, b.name);
b.score = s.score;
strcpy(b.name, s.name);
}
};
int main()
{
information student[20];
int n, i = 0, j = 0;
cin >> n;
for (i = 0; i < n; i++)
{
student[i].get();
}
for (i = 0; i < n - 1; i++)
{
for (j = 0; j < n - 1 - i; j++)
{
if (student[j].Name() < student[j + 1].Name())
{
exchange(student[j], student[j + 1]);
}
}
}
for (i = 0; i < n - 1; i++)
{
for ( j = 0; j < n - 1 - i; j++)
{
if (student[j].Score() < student[j + 1].Score())
{
exchange(student[j], student[j + 1]);
}
}
}
cout << "排序后:" << endl;
for (i = 0; i < n; i++)
{
student[i].show();
}
return 0;
}