2410
This commit is contained in:
11
include/solution/2410.h
Normal file
11
include/solution/2410.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#ifndef INC_2410_H
|
||||||
|
#define INC_2410_H
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
int matchPlayersAndTrainers(int *players, int playersSize, int *trainers, int trainersSize);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
30
src/2410.c
Normal file
30
src/2410.c
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#include <solution/2410.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int cmp(const void *a, const void *b)
|
||||||
|
{
|
||||||
|
return *(int *)a - *(int *)b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int matchPlayersAndTrainers(int *players, int playersSize, int *trainers, int trainersSize)
|
||||||
|
{
|
||||||
|
qsort(trainers, trainersSize, sizeof(int), cmp);
|
||||||
|
qsort(players, playersSize, sizeof(int), cmp);
|
||||||
|
|
||||||
|
int match = 0;
|
||||||
|
for (int i = 0, j = 0; i < playersSize && j < trainersSize; i++)
|
||||||
|
{
|
||||||
|
for (; j < trainersSize; j++)
|
||||||
|
{
|
||||||
|
if (trainers[j] >= players[i])
|
||||||
|
{
|
||||||
|
match++;
|
||||||
|
j++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return match;
|
||||||
|
}
|
||||||
14189
tests/test_2410.cpp
Normal file
14189
tests/test_2410.cpp
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user