View Code of Problem 100

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

struct music
{
	char name[50];
	int m,s;
	int score = 0;
}num[105];

int main()
{
	int n, t;
	char s[50];
	int x, y;
	scanf("%d", &n);
	while(n != 0)
	{
		for(int i = 0; i < n; i++)
		{
			scanf("%s", num[i].name);
			scanf("%d:%d", &num[i].m, &num[i].s);
			num[i].s += 60 * num[i].m;
		}
		scanf("%d", &t);
		while(t--)
		{
			scanf("%s", s);
			scanf("%d:%d", &x, &y);
			y += x * 60;
			for(int i = 0; i < n ;i++)
				if(strcmp(s, num[i].name) == 0)
					num[i]->score += 5.0 * y / num[i].s;
		}
		for(int i = 0; i < n ; i++)
		{
			int pos = 0;
			for(int j = 1; j < n; j++)
			{
				if(num[j]->score > num[pos]->score)
					pos = j;
				else if(num[j]->score == num[pos]->score)
					if(strcmp(num[j].name, num[pos].name) < 0)
						pos = j;
			}
			printf("%s %d\n", num[pos].name, num[pos]->score);
			num[pos]->score = -1;
		}
		scanf("%d", &n);
	}
	
	return 0;
 } 
/*
Main.c:8:12: error: expected ':', ',', ';', '}' or '__attribute__' before '=' token
  int score = 0;
            ^
Main.c: In function 'main':
Main.c:33:12: error: invalid type argument of '->' (have 'struct music')
      num[i]->score += 5.0 * y / num[i].s;
            ^
Main.c:40:14: error: invalid type argument of '->' (have 'struct music')
     if(num[j]->score > num[pos]->score)
              ^
Main.c:40:32: error: invalid type argument of '->' (have 'struct music')
     if(num[j]->score > num[pos]->score)
                                ^
Main.c:42:19: error: invalid type argument of '->' (have 'struct music')
     else if(num[j]->score == num[pos]->score)
                   ^
Main.c:42:38: error: invalid type argument of '->' (have 'struct music')
     else if(num[j]->score == num[pos]->score)
                                      ^
Main.c:46:45: error: invalid type argument of '->' (have 'struct music')
    printf("%s %d\n", num[pos].name, num[pos]->score);
                                             ^
Main.c:47:12: error: invalid type argument of '->' (have 'struct music')
    num[pos]->score = -1;
            ^
*/

Double click to view unformatted code.


Back to problem 100