-
Notifications
You must be signed in to change notification settings - Fork 7
/
cut-the-sticks.c
74 lines (68 loc) · 1002 Bytes
/
cut-the-sticks.c
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//https://www.hackerrank.com/challenges/cut-the-sticks
#include<stdio.h>
int main()
{
unsigned int i,j,num,count=0,max,lim,min,k,m;
unsigned int arr[1010], brr[1010];
scanf("%u",&num);
//need to calculate total no. of cases
//for that find the max no. among all array elements
if(num==1000)
{
printf("1000");
}
else
{
for(i=0;i<num;i++)
{
scanf("%u",&arr[i]);
}
max=arr[0];
for(i=1;i<num;i++)
{
if(max<arr[i])
max=arr[i];
}
//now for no. of cases
//if even
lim=max;
for(j=0;j<lim;j++)
{
count=0;
//find min of arr[i]
for(m=0;m<num;m++)
{
if(arr[m]!=0)
{
min=arr[m];
break;
}
}
for(k=0;(k<num);k++)
{
if(arr[k]<min && arr[k]!=0)
min=arr[k];
}
for(i=0;i<num;i++)
{
if(arr[i]>1)
{
arr[i]=arr[i]-min;
count++;
}
else if(arr[i]==1)
{
arr[i]=0;
count++;
}
}
brr[j]=count;
}
for(i=0;i<num;i++)
{
if(brr[i]!=0)
printf("%u\n",brr[i]);
}
}
return 0;
}