hey
what's wrong with this code for alien rhyme (got WA):
###########The Code############
const readline = require('readline');
var rl = readline.createInterface(process.stdin, process.stdout);
var TCNum=0;
var TCmax=null;
var waitFor='T';
var n;
var wl=[];
var thisWord;
var thatWord;
var mathed=0;
var isPair=-1;
var wordCount=0;
rl.on('line', function(data) {
if(waitFor=='T'){
TCmax=parseInt(data);
waitFor='N';
}else if(waitFor=='N'){
n=parseInt(data);
wl=[];
waitFor='W';
}else if(waitFor=='W'){
wl.push(data);
if(wl.length==n)
{
wordCount=0;
while(wl.length)
{
thisWord=wl[0];
isPair=-1;
for(var i=0;i<thisWord.length;i++)
{
mathed=0;
for(var ii=1;ii<wl.length;ii++)
{
thatWord=wl[ii];
if(thisWord.substr(thisWord.length-1-i)==thatWord.substr(thatWord.length-1-i))
{
mathed++;
isPair=ii;
}
}
if(mathed<=1)
{
break;
}
}
if(mathed==1)
{
wordCount++;
wl.splice(isPair,1);
wl.splice(0,1);
}else{
wl.splice(0,1);
}
}
console.log("Case #"+(TCNum+1)+": "+(wordCount*2));
waitFor='N';
checkCount();
}
}
function checkCount()
{
TCNum++;
if(TCNum==TCmax)
{
rl.close();
}
}
}).on('close',function(){
process.exit(0);
});
###############################
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/ca892a8e-385c-450a-b996-27c9634ff647%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.