Skip to content

Instantly share code, notes, and snippets.

@alucky0707
Created May 3, 2013 07:05
Show Gist options
  • Save alucky0707/5507643 to your computer and use it in GitHub Desktop.
Save alucky0707/5507643 to your computer and use it in GitHub Desktop.
AOJ 105
function main() {
var
i,
line, words,
dict = {},
len = input.length;
input.forEach(function(line) {
if(line.trim() === '') return;
line = line.split(' ');
if(!dict[line[0]]) {
dict[line[0]] = [];
}
dict[line[0]].push(parseInt(line[1], 10));
});
words = Object.keys(dict);
words.sort();
words.forEach(function(word) {
dict[word].sort(function(a, b){
return a - b;
});
console.log(word);
console.log(dict[word].join(' '));
});
}
var
input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
input += chunk;
});
process.stdin.on('end', function() {
input = input.split('\n');
main();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment