Skip to content

Instantly share code, notes, and snippets.

@theabbie
Created April 4, 2020 10:13
Show Gist options
  • Save theabbie/e92ff4afa69623af283ea9d5b19023dd to your computer and use it in GitHub Desktop.
Save theabbie/e92ff4afa69623af283ea9d5b19023dd to your computer and use it in GitHub Desktop.
function processData(input) {
var i = 1;
var lines = input.split("\n");
var t = parseInt(lines[0]);
for (l=0; l<t; l++) {
var n = parseInt(lines[i]);
i++;
var mat = lines.slice(i,i+n).map((m,v)=>[...m.split(" ").map(s=>parseInt(s)),v]);
mat.sort(function(a,b) {return a[0]-b[0]})
var possible = true;
var ans = [];
ans[mat[0][2]] = "J";
var j,c;
j = mat[0];
c=[0,0];
for (x=1; x<mat.length; x++) {
if (mat[x][0]>=j[1]) {ans[mat[x][2]]="J";j=mat[x];}
else if (mat[x][0]>=c[1]) {ans[mat[x][2]]="C";c=mat[x];}
else {possible = false; break;}
}
console.log("Case #"+(l+1)+": "+(possible?ans.join(""):"IMPOSSIBLE")+"\n");
i+=n;
}
}
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