neebanv
BAN USERComparison should be based on appending one number at the from of other and vice versa.
#include <iostream>
#include <cmath>
#include <algorithm>
int numDigits(int num)
{
return floor(log10(num)) + 1;
}
bool myCompare(int dig1, int dig2)
{
int numDig1 = numDigits(dig1);
int numDig2 = numDigits(dig2);
int dig11 = dig1 * pow(10, numDig2) + dig2;
int dig22 = dig2 * pow(10, numDig1) + dig1;
if(dig22 > dig11)
{
return false;
}
return true;
}
int main()
{
int array[] = {1, 5, 8, 19, 21, 9, 100};
/// Biggest no: 9|8|5|21|19|1|100;
/// Sort the list in a order, of their Most Significant Bit.
int size = sizeof(array)/sizeof(int);
std::sort(array, array+size, myCompare);
for(int i=0; i < size; i++)
{
std::cout << array[i];
}
std::cout << std::endl;
}
Even number of odd digits,
Eg : 9942, 11, 101 etc.
#include <iostream>
bool evenNumOddDigits(int num)
{
int count = 0;
while(num)
{
int rem = num % 10;
num = num/10;
if(rem % 2)
{
count++;
}
}
if(count % 2 == 0 and count > 0) return true;
return false;
}
int main()
{
int count = 0;
for (int i = 0; i < 10000; i++)
{
if(evenNumOddDigits(i))
{
// std::cout << i << std::endl;
count++;
}
}
std::cout << count;
return 0;
}
There is a recursive solution for this problem. Please read through.
#include <stdio.h>
int func(int, int);
main()
{
int M,C;
scanf("%d%d",&M,&C);
printf("%d\n",func(M,C));
}
int func(int M, int C)
{
if(M==1 && C==1)
{
// printf("(1,1,1)\n(0,0,0)\n");
return 1;
}
else if(M==2 && C==2)
{
// printf("(2,2,1)\n(1,1,0)\n(2,1,1)\n(0,1,0)\n(1,1,1)\n(0,0,0)\n");
return 5;
}
else if(M == C)
{
/* printf("(%d,%d,1)\n(%d,%d,0)\n",M,C,M-1,C-1);
printf("(%d,%d,1)\n(%d,%d,0)\n",M,C-1,M,C-3);
printf("(%d,%d,1)\n(%d,%d,0)\n",M,C-2,M-2,C-2);
*/ return (6+func(M-1,C-1));
}
else //case where M > C
{
int i;
// for(i=0;i<(M-C);i++)
// printf("(%d,%d,1)\n(%d,%d,0)\n",M-i,C,M-(i+1),C-1);
return 2*(M-C)+func(C,C);
}
}
Here is a naive solution :
Suppose we have points N points, say .. {a, b, c, d, e .. N }
1. Create a matrix of N X N matrix, M.
2. Find the euclidean distance of each pair of elements and fill the matrix. We need to calculate only (N*N)/2 pairs. since M (b, a) = M (a, b).
3. Create a matrix of N X 3, namely OUT.
Find 3 lowest elements in order from each row and fill the first row of OUT.
RepBimerLaura, Area Sales Manager at Bloomberg LP
I am a Job training specialist conducting training programs that will boost employees workplace performance in alliance with the company ...
Replyndaander9, Analyst at A9
My name is Anderson and I am a 24 years old trader born and currently working in New York, USA ...
C++ Code For finding Connected Components.
- neebanv November 15, 2015