7-37 模拟EXCEL排序 (25分)--优先队列
标签:std main 字符串大小 bre 大小 else excel %s bsp
#include
#include
#include using namespace std;
int C;
int cmp(const char a[], const char b[])//比较字符串大小的函数
{
for (int i = 0; i 10; i++)
{
if (a[i] == ‘\0‘ || b[i] == ‘\0‘)
break;
if (a[i] == b[i])
{
if (a[i] != ‘\0‘)
continue;
else
break;
}
else if (a[i] > b[i])
{
return 1;
}
else
return -1;
}
return 0;
}
struct node//结构体定义
{
char num[10];
char name[10];
int score;
bool operator const struct node& a)const
{
if (C == 1)
{
return (cmp(num, a.num) == 1);
}
else if (C == 2)
{
if (cmp(name, a.name) == 0)
{
return (cmp(num, a.num) == 1);
}
else if (cmp(name, a.name) == 1)
return true;
else return false;
}
else if (C == 3)
{
if (score == a.score)
return (cmp(num, a.num) == 1);
else
return score > a.score;
}
}
};
int main()
{
priority_queuestruct node> q;
int N;
cin >> N >> C;
for (int i = 0; i )
{
struct node t_node;
cin >> t_node.num >> t_node.name >> t_node.score;
q.push(t_node);
}
while (!q.empty())
{
//cout //用cout会超时
printf("%s %s %d\n", q.top().num, q.top().name, q.top().score);
q.pop();
}
return 0;
}
7-37 模拟EXCEL排序 (25分)--优先队列
标签:std main 字符串大小 bre 大小 else excel %s bsp
原文地址:https://www.cnblogs.com/2020R/p/12770856.html
评论