SS7
BAN USERSimple C++ code
#include<iostream>
using namespace std;
bool colorful(int *,int );
int main()
{
int number = 0;
int *a = new int[10];
memset(a,NULL,10);
int i=1;
char num_length[10];
cout<<"Enter number"<<endl;
cin>>number;
itoa(number,num_length,10);
while(number>0)
{
a[strlen(num_length)-i] = number%10;
number = number/10;
++i;
}
for(int i=0;i<strlen(num_length);i++)
{
if(a[i] == 1 || a[i] == 0 )
{
cout<<"Not a colorful number"<<endl;
delete []a;
return 0;
}
}
bool result = colorful(a, strlen(num_length));
if(result)
cout<<"Colorful"<<endl;
else
cout<<"Not a colorful number"<<endl;
delete []a;
return 0;
}
bool colorful(int *a,int length)
{
int i=0,temp=length;
while(1)
{
a[temp]=a[i]*a[i+1];
temp++;
i++;
if(i==length-1)
break;
}
a[temp]=1;
for(int i =0;i<=temp;i++)
a[temp]=a[temp]*a[i];
int j =0,check ;
while(j<temp)
{
check = a[j];
for(int i=j+1;i<=temp;i++)
{
if(check == a[i] )
return false;
}
++j;
}
return true;
}
Hi,
- SS7 August 22, 2013Can you please share your experience ?
Thanks