They are given in natural numbers. List the digits that appear in the decimal notation of these numbers in ascending order of occurrence. If two digits have the same number of occurrences, the smaller digit will be displayed first.
The Example:
In
5 124 229 1322 4 534
Out
5 9 1 3 4 2
This is my code:
#include <iostream>
using namespace std;
int v1[10],v2[10],lim,x,ok;
int main()
{
cin>>lim;
for(int i=1; i<=lim; i++)
{
cin>>x;
while (x>0)
{
v1[x&10]++;
v2[x%10]=x%10;
x=x/10;
}
}
while (!ok)
{
ok=1;
for(int i=0; i<=lim; i++)
{
if(v1[i]>v1[i+1])
{
swap (v1[i],v1[i+1]);
swap (v2[i],v2[i+1]);
ok=0;
}
}
}
ok=0;
while (!ok)
{
ok=1;
for(int i=0; i<lim; i++)
{
if(v2[i]>v2[i+1])
if(v1[i]==v1[i+1])
swap (v2[i],v2[i+1]);
}
}
for (int i=0; i<=10; i++)
{
if(v2[i]!=0)
cout<<v2[i]<<" ";
}
}
It won't sort the way I want
I've tried to sort it 2 times