re: Daily Coding Puzzles - Nov 4th - Nov 9th VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Friday The Last Word (CodeJam): You are the next contestant on this show, and the host has just showed you the string S. What's the winning last...
 

TypeScript

function processLastwordData(input :string) : void {
    const inputArray = input.split('\n');
    let resultStr = "";
    const cases = parseInt(inputArray[0]);
    for(let i=1; i <= cases; i++) {
        resultStr += `Case #${i}: ${lastWord(inputArray[i])}\n`
    }
    process.stdout.write(resultStr);
}

function lastWord(str : string) : string {
    let outStr = str[0];
    for(let i=1; i<str.length; i++) {
        if(str.charCodeAt(i) >= outStr.charCodeAt(0)) outStr = str[i] + outStr;
        else outStr = outStr + str[i];
    }
    return outStr;
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
let _input = "";
process.stdin.on("data", function (input) {
    _input += input;
});
process.stdin.on("end", function () {
    processLastwordData(_input);
});

code of conduct - report abuse