-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcounting.c
More file actions
53 lines (44 loc) · 811 Bytes
/
counting.c
File metadata and controls
53 lines (44 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
int countof(int arr[], int n);
void solution(int arr[]);
int main (void)
{
int a = 0;
int count;
int arr[100] = {2, 5, 4 ,5 ,2 ,1, 2}; //받은 값
//printf("%i\n",countof(arr, 5));
solution(arr);
}
int countof(int arr[], int n)
{
int count = 0;
for (int i = 0; arr[i] != 0; i++)
{
if (arr[i] == n)
{
count++;
arr[i] = -1;
}
}
return count;
}
void solution(int arr[])
{
int a = 0;
int answer[100];
for (int i = 0; arr[i] > 0; i++)
{
int n = arr[i];
int count = countof(arr, n);
if (count > 1)
{
printf("%i\n", count);
answer[a] = count;
a++;
}
}
if (a == 0)
{
printf("-1\n");
}
}