outdoor
BAN USERvoid GetSum(array<int> input, int N)
{
if(N == 0)
{
int sum = 0;
for(int i = 1; i < input.length; i++)
{
sum += input[i] ;
}
return sum;
}
if(input.length == 1)
{
return 0;//error
}
int temp[input.length -1];
for(int i = 1; i < input.length; i++)
{
temp[i-1] = input[i];
}
for(int j = 0; j < temp.length; j++)
{
temp[j] = temp[j] - input[j];
}
GetSum(temp, N--);
}
To simplify issue, assuming the dictionary and list are both array of char, just like your example.
bool ShortestSeq(array<char> D, array<char> L)
{
int finalStart = 0;
int finalEnd = 0;
int shortestLength = 0;
int start = -1;
int end = 0;
int j = 0;
for(int i = 0; i < D.length; i++)
{
if(D[i] == L[0])
{
start = -1;
j = 0;
}
if(start == -1 && D[i] = L[j])
{
if(++j >= L.length)
{
finalStart = i;
finalEnd = i;
return true;
}
start = i;
}
else if(start >=0 && D[i] == L[j])
{
if(++j >= L.length)
{
end = i;
int length = end - start;
if(length < shortestLength)
{
finalStart = start;
finalEnd = end;
}
else
{
j = 0;
start = -1; //continue search
}
}
}
}
}
Using 6 for loops to output 6! which is 120 permutations.
void permutation()
{
char input[6] = {'c', 'a', 'b', 'r' ,'o','n'};
char output[6];
for(int i = 0; i < 6; i++)
{
output[0] = input[i];
for(int j = 0; j < 6; j++)
{
if(input [j] != output[0])
{
output[1] = input[j];
}
for(int k = 0; k< 6; k++)
{
..........
printf(output);
}
}
}
}
Seems to me, this is a database question. We would need to put millions of records into database first.
- outdoor March 30, 2013