HuynhCongBaoTran
BAN USER/*
chars[] = [ "a" , "a" , "n" , "c" , "b"]
bit[] = [ ]//0 or 1
callling this function is pretty expensive
*/
bool IsThisWordGood(wrd, chars[])
{
bool res = false;
char charWord;
bit bitSet[length(chars[])]
ResetZeroBit(bitSetOff);
for (int x = 0;x<length(wrd);x++)
{
res = false;
charWord = wrd[x];
for (int i = 0;i<length(chars[]) && res == false; i++)
{
if (chars[i] == charWord && bitSet[i]==0)
{
bitSet[i]=1;
result = true;
}
}
}
return res;
}
/*
The worst case is:
wrds[] has all the words with the same length and in the chars[]
/*
word* function (wrds[] , chars[])
{
word longestWord[];//the worst case longestWord[] = wrds[]
int longestLengthOfWord = 0
int i =0, j =0;
if(IsEmpty(wrds[]) || IsEmpty(wrds[chars]))
{
return null;
}
SortDecreasingOrder(wrds[]);
longestLengthOfWord = GetNumberOfChar(wrds[0])
for(i =0; i<length(wrds[]) && (j == 0 || longestLengthOfWord == GetNumberOfChar(wrds[i]));i++)
{
if(IsThisWordGood(wrds[i], chars[]) == true)
{
longestLengthOfWord = GetNumberOfChar(wrds[i]);
longestWord[j] = wrds[i];
j++;
}
}
return longestWord;
}
/*
- HuynhCongBaoTran February 08, 2014Running time is terrible
*/
Original[n][n];
result[n+1][n+1];
for(row =0; row < NumOfRow; row++)
{
result[row][n] = 1;
for(col=0;col<NumOfColumn;col++)
{
result[row][n] = result[row][n] * Original[row][col] //last row cell
result[n][col] = result[row][n] * Original[row][col] //last col cell
}
}
for(row =0; row < NumOfRow; row++)
{
for(col=0;col<NumOfColumn;col++)
{
if(result[row][n] * result[n][col] > 0)
{
result[row][col] = 1;
}
else if (result[row][n] * result[n][col] == 0)
{
result[row][col] = 0;
}
else
{
result[row][col] = -1;
}
}
}