网易2019-泡泡群成员显示排序

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zh1204190329/article/details/81591304

题干暂时忘了。先显示在线成员,然后按照成员权限排序,最后按照成员昵称的字节序 排序。

#include <iostream>
#include <queue>
#include <assert.h>
#include <stdio.h>
#include <algorithm>
#include<cstdlib>

using namespace std;

typedef struct _MemberInfo
{
    bool state;  // 成员状态: 1, 成员在线;  0, 离线
    int position;  // 成员身份, 0为普通成员, 1为管理员, 2为拥有者
    string name;  //  成员昵称
}MemberInfo;


bool cmp1(MemberInfo x, MemberInfo y)
{
	// 在线人员比离线人员靠前显示
    if (x.state != y.state)
        return x.state > y.state;
    else
    {
		// 显示次序: 拥有者 , 管理员, 普通成员
        if (x.position != y.position)
            return x.position > y.position;
        else
			// 若当前2人状态以及身份相同,则按照名字的字典序从小到大排序
            return x.name < y.name;
    }
}

int main()
{
    MemberInfo a[100];
    MemberInfo b[100];
	
	// 群组人数
    int N = 0;
    cin >> N;
    for(int i = 0; i < N; i++)
    {
		// 输入每一位成员的身份和昵称
        cin >> a[i].position >> a[i].name;
		// 成员默认为离线状态
        a[i].state = 0;
    }

	// M个成员的状态变化记录
    int M = 0;
    cin >> M;
    for (int i = 0; i < M; i++)
    {
        cin >> b[i].name >> b[i].state;
        for (int j = 0; j < N; j++)
        {
			//  输入成员昵称和状态操作,1表示上线,0表示下线
             if (b[i].name == a[j].name)
             {
                 a[j].state = b[i].state;
             }
        }
    }

    sort(a, a+N , cmp1);
    for (int i = 0; i < N; i++)
    {
        cout << a[i].name << endl;
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/zh1204190329/article/details/81591304