Language: C




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

#define MAXN	300001
int CardCounter[MAXN];
struct sCard
{
	int kind;
	int ONum; // Original Number
};
sCard Card[MAXN];
sCard TempCard[MAXN];

void Swap(sCard *x, sCard *y)
{
	sCard Temp = *x;
	*x = *y;
	*y = Temp;
}




int compare(const void *a, const void *b)   
{
	sCard *num1 = (sCard *)a;    
	sCard *num2 = (sCard *)b;    

	if (num1->ONum > num2->ONum)
		return -1;    

	if (num1->ONum < num2->ONum)
		return 1;   

	return 0;    
}


void Sort(int N, sCard *Card)
{
/*	for (int i = 0; i < N; i++)
		for (int j = i; j < N; j++)
			if (Card[i].ONum < Card[j].ONum)
				Swap(&Card[i], &Card[j]);
	*/			
	qsort(Card, N, sizeof(sCard), compare);
}




int main()
{
#ifdef _WIN32
	freopen("input.txt", "r", stdin);
#endif

	int N;
	scanf("%d", &N);

	for (int n = 0; n < N; n++)
	{
		int t = 0;
		scanf("%d", &t);
		CardCounter[t]++;
	}


	int CardIndex = 0;
	int _CardIndex = 0;
	for (int n = 0; n < MAXN; n++)
	{
		if (CardCounter[n])
		{
			Card[CardIndex].kind = n;
			Card[CardIndex].ONum = CardCounter[n];
			CardIndex++;
		}
	}

	_CardIndex = CardIndex;
	Sort(CardIndex, Card);
#ifdef _WIN32
	printf("CardIndex : %d\n", _CardIndex);
	for (int i = 0; i < CardIndex; i++)
		printf("Card %d : %d\n", Card[i].kind, Card[i].ONum);
#endif


	printf("%d\n", N); // case 1
	for (int K = 2; K <= N; K++)
	{
		// ReInit
		CardIndex = _CardIndex;
		memcpy(TempCard, Card, sizeof(sCard)*CardIndex);

		int OperationCnt = 0;
		while (K <= CardIndex)
		{
			int LastMem = K - 1;
			int KillCnt = 0;
			for (int i = 0; i < LastMem; i++)
			{
				TempCard[i].ONum -= TempCard[LastMem].ONum;
				if (TempCard[i].ONum == 0)
					KillCnt++;
			}

			OperationCnt += TempCard[LastMem].ONum;
			TempCard[LastMem].ONum = 0;
			KillCnt++;

			Sort(CardIndex, TempCard);
			CardIndex -= KillCnt;
		}

		printf("%d\n", OperationCnt);
	}



	return 0;
}

Compiler output:
main.c:15:1: error: unknown type name 'sCard'; use 'struct' keyword to refer to the type
   15 | sCard Card[MAXN];
      | ^~~~~
      | struct 
main.c:16:1: error: unknown type name 'sCard'; use 'struct' keyword to refer to the type
   16 | sCard TempCard[MAXN];
      | ^~~~~
      | struct 
main.c:18:11: error: unknown type name 'sCard'
   18 | void Swap(sCard *x, sCard *y)
      |           ^~~~~
main.c:18:21: error: unknown type name 'sCard'
   18 | void Swap(sCard *x, sCard *y)
      |                     ^~~~~
main.c: In function 'compare':
main.c:30:9: error: unknown type name 'sCard'; use 'struct' keyword to refer to the type
   30 |         sCard *num1 = (sCard *)a;
      |         ^~~~~
      |         struct 
main.c:30:24: error: 'sCard' undeclared (first use in this function)
   30 |         sCard *num1 = (sCard *)a;
      |                        ^~~~~
main.c:30:24: note: each undeclared identifier is reported only once for each function it appears in
main.c:30:31: error: expected expression before ')' token
   30 |         sCard *num1 = (sCard *)a;
      |                               ^
main.c:31:16: error: 'num2' undeclared (first use in this function); did you mean 'num1'?
   31 |         sCard *num2 = (sCard *)b;
      |                ^~~~
      |                num1
main.c:31:31: error: expected expression before ')' token
   31 |         sCard *num2 = (sCard *)b;
      |                               ^
main.c:33:17: error: request for member 'ONum' in something not a structure or union
   33 |         if (num1->ONum > num2->ONum)
      |                 ^~
main.c:36:17: error: request for member 'ONum' in something not a structure or union
   36 |         if (num1->ONum < num2->ONum)
      |                 ^~
main.c: At top level:
main.c:43:18: error: unknown type name 'sCard'
   43 | void Sort(int N, sCard *Card)
      |                  ^~~~~
main.c: In function 'main':
main.c:79:40: error: request for member 'kind' in something not a structure or union
   79 |                         Card[CardIndex].kind = n;
      |                                        ^
main.c:80:40: error: request for member 'ONum' in something not a structure or union
   80 |                         Card[CardIndex].ONum = CardCounter[n];
      |                                        ^
main.c:86:9: error: implicit declaration of function 'Sort' [-Wimplicit-function-declaration]
   86 |         Sort(CardIndex, Card);
      |         ^~~~
main.c:99:47: error: 'sCard' undeclared (first use in this function)
   99 |                 memcpy(TempCard, Card, sizeof(sCard)*CardIndex);
      |                                               ^~~~~
main.c:108:44: error: request for member 'ONum' in something not a structure or union
  108 |                                 TempCard[i].ONum -= TempCard[LastMem].ONum;
      |                                            ^
main.c:108:70: error: request for member 'ONum' in something not a structure or union
  108 |                                 TempCard[i].ONum -= TempCard[LastMem].ONum;
      |                                                                      ^
main.c:109:48: error: request for member 'ONum' in something not a structure or union
  109 |                                 if (TempCard[i].ONum == 0)
      |                                                ^
main.c:113:58: error: request for member 'ONum' in something not a structure or union
  113 |                         OperationCnt += TempCard[LastMem].ONum;
      |                                                          ^
main.c:114:42: error: request for member 'ONum' in something not a structure or union
  114 |                         TempCard[LastMem].ONum = 0;
      |                                          ^