PTA: quietly concerned (25 points) (c language version)

There is a "quiet concern", a user quietly concerned about people on Sina Weibo, does not appear on the list of the user's attention, but will people push it quietly concerned about microblogging published to the user. Now we do a detective back to the network, according to a person's watchlist and their thumbs situation to other users, who might have been raking it quietly concerned.

Input format:
input is first given a list of user interest in the first row, the following format:

The number N User 1 User 2 User N ......

Where N is a positive integer not exceeding 5000, for each user i (i = 1, ..., N) which is the user ID is concerned, is a string of numbers and English letters of 4 bits, the room separated by a space.

After the information is given to the user's thumbs: Firstly, a positive integer of not more than 10000 M, followed by M rows, each row is given by its point like a user ID and the number of times the user's thumbs (1000 ), separated by a space. Note: The user ID is the unique identifier of a user. Topic ensure no repeat users concerned about the list, there is no point in repeating information like user.

Output format:
we believe that is greater than the number of users praise thumbs point average, and not people on their list of concerns, is likely to be quietly concerned about their people. Under this assumption, you output in ascending alphabetical order of user ID may be quietly concerned about their people, each row an ID. If in fact there is no such person, then the output "Bing Mei You".

Input Sample. 1:
10 GAO3 Magi Zha1 Sen1 Quan FaMK LSum Eins FATm Llao
. 8
Magi 50
Pota 30
Llao. 3
Ammy 48
Dave 15
GAO3 31 is
Zoro. 1
Cath 60

Output Sample 1:
Ammy
Cath
Pota

Input Sample 2:
. 11 GAO3 Magi Zha1 Sen1 Quan FaMK LSum Eins FATm Llao Pota
. 7
Magi 50
Pota 30
Llao 48
Ammy. 3
Dave 15
GAO3 31 is
Zoro 29

Output Sample 2:
Bing Mei by You

C ++ without the map, a maximum 10 points scale with c language can not, ask big brother advice.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct prisePeople
{
	char name[5];
	int n;
};

int AVERAGE;
int averfunc(struct prisePeople *p, int n);
//void properPerson(char *p1, struct prisePeople *p2, int n1, int n2);
//错误使用指针, 二维数组应该用数组指针而我使用了普通指针
void properPerson(char (*p1)[5], struct prisePeople *p2, int n1, int n2);
int cmpfunc(const void *elem1, const void *elem2);

int main()
{
	int i, j, n1, n2;
	char people[5000][5];
	struct prisePeople a[10000];

	scanf("%d", &n1);
	for (i = 0; i < n1; i++)
		scanf("%s", people[i]);
	scanf("%d", &n2);
	for (i = 0; i < n2; i++)
		scanf("%s %d", a[i].name, &a[i].n);
	AVERAGE = averfunc(a, n2);
	properPerson(people, a, n1, n2);

	return 0;
}
int averfunc(struct prisePeople *p, int n)
{
	int i, sum, average;

	sum = average = 0;
	for (i = 0; i < n; i++)
		sum += p[i].n;
	average = sum / n;

	return average;
}
void properPerson(char (*p1)[5], struct prisePeople *p2, int n1, int n2)
{
	int i, j, k, m, flag = 0;
	char a[5000][5];

	for (i = 0, k = 0; i < n2; i++, p2++)
		if (p2->n > AVERAGE)
			strcpy(a[k++], p2->name);
	m = 0;
    for (i = 0; i < k; i++)
    {
        int flag2 = 1;
        for (j = 0; j < n1; j++)
        {
            if (strcmp(a[i], p1[j]) == 0)
                flag2 = 0;
        }
        if (flag2)
        {
            strcpy(a[m++], a[i]);
            flag = 1;
        }
    }
	qsort(a, m, sizeof(a[0]), cmpfunc);
	if (flag)
	    for (i = 0; i < m; i++)
            printf("%s\n", a[i]);
    else
        printf("Bing Mei You\n");
}
int cmpfunc(const void *elem1, const void *elem2)
{
    char *p1 = (char*)elem1;
    char *p2 = (char*)elem2;

    return strcmp(p1, p2);
}
Published 24 original articles · won praise 0 · Views 145

Guess you like

Origin blog.csdn.net/qq_45624989/article/details/105152621