- issue to be resolved:segmantation fault
Code:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
bool cmp (int a,int b){
return a > b ;
}
int main()
{
int k;
cin>>k;
int *n_input;
int flag[101];
int m = 0 ;
memset(flag,0,101*sizeof(int));
int temp = 0 ;
n_input = (int *)malloc(sizeof(int)*k);
for(int i = 0 ;i < k ;i++){
cin>>n_input[i];
if(flag[n_input[i]]==0){
temp = n_input[i];
if(flag[temp]==0)
while(temp!=1){
if(temp%2==0) {
temp/=2;
flag[temp]=1;
}
else {
temp=(temp*3+1)/2;
flag[temp]=1;
}
}
}
}
sort(n_input,n_input+k,cmp);
for(int i = 0 ;i < k ; i ++){
if(flag[n_input[i]]==0) m ++;
}
for(int i = 0 ; i < k ; i ++){
if(flag[n_input[i]]==0){
if(m==1)
cout<<n_input[i];
else{
cout<<n_input[i]<<" ";
m--;
}
}
}
free(n_input);
return 0;
}