forked from amankayat/HackerRank-Solution-Algorithm-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcutthesticks.cpp
60 lines (44 loc) · 795 Bytes
/
cutthesticks.cpp
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
#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
vector<int> cutthesticks(vector<int> a){
int zero =0;
vector<int> store;
while(zero<a.size()){
store.push_back( a.size() -zero);
//find min
int min = 1001;
for(int i=0;i<a.size();i++){
if(a[i]>0 && a[i]<min){
min = a[i];
}
}
//
for(int i=0;i<a.size();i++){
a[i] = a[i]-min;
if(a[i]==0){
zero++;
}
}
}
return store;
}
int main(){
int n,count=0;
cin>>n;
vector<int> a;
vector<int> result;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
a.push_back(x);
}
result = cutthesticks(a);
//print the array
for(int i=0;i<result.size();i++)
{
cout<<result[i]<<"\n";
}
}