Created
March 21, 2016 18:36
-
-
Save jianminchen/8899cb7587b0389e6ff6 to your computer and use it in GitHub Desktop.
Two string - JavaScript, things I like: using j== first.length to determine YES/ NO, the big problem of coding - repeat same code in if/ else code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function processData(input) { | |
//Enter your code here | |
var inputs = input.split('\n'); | |
var t = parseInt(inputs[0]); | |
for(var i = 0; i < t; i++ ){ | |
var first = inputs[2*i+1]; | |
var second = inputs[2*i+2]; | |
if(first.length < second.length){ | |
for(var j = 0; j <first.length; j++){ | |
if(second.indexOf(first[j]) != -1) | |
break; | |
} | |
if(j==first.length) | |
console.log("NO"); | |
else | |
console.log("YES"); | |
}else{ | |
for(var j = 0; j <second.length; j++){ | |
if(first.indexOf(second[j]) != -1) | |
break; | |
} | |
if(j==second.length) | |
console.log("NO"); | |
else | |
console.log("YES"); | |
} | |
} | |
} | |
process.stdin.resume(); | |
process.stdin.setEncoding("ascii"); | |
_input = ""; | |
process.stdin.on("data", function (input) { | |
_input += input; | |
}); | |
process.stdin.on("end", function () { | |
processData(_input); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment