#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <new>
using namespace std;
bool isallzero(int *arr, int sz)
{
bool state=1;
for(int i=0;i<sz;i++)
{
if(*(arr+i)!=0)
{
state=0;
break;
}
}
return state;
}
int minstick(int *arr, int sz)
{
int finmin=0;
for(int i=0;i<sz;i++)
{
if(*(arr+i)!=0)
{
finmin= *(arr+i);
break;
}
}
for(int i=0;i<sz;i++)
{
if(*(arr+i)<finmin && *(arr+i)!=0)
{
finmin= *(arr+i);
}
}
return finmin;
}
int numcounter(int *arr, int sz)
{
int count=0;
for(int i=0;i<sz;i++)
{
if(*(arr+i)!=0)
{
count++;
}
}
return count;
}
void cutoperation(int *arr, int sz)
{
int mins= minstick(arr,sz);
if(mins==0)
{
return;
}else
{
for(int i=0;i<sz;i++)
{
if(*(arr+i)!=0)
{
*(arr+i)-= mins;
}
}
}
}
void disparr(int *arr, int sz)
{
for(int i=0;i<sz;i++)
{
cout << *(arr+i) << " ";
}
cout << endl;
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int N;
cin >> N;
int *arr = new int [N];
for(int i=0;i<N;i++)
{
cin >> arr[i];
}
while(!isallzero(arr,N))
{
cout << numcounter(arr,N) << endl;
cutoperation(arr,N);
}
/*
cutoperation(arr,N);
disparr(arr,N);
cutoperation(arr,N);
disparr(arr,N);
cutoperation(arr,N);
disparr(arr,N);
cutoperation(arr,N);
disparr(arr,N);
*/
return 0;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.