Created
October 15, 2016 17:36
-
-
Save tennisonchan/493a53a6fa14f5ada2e4d7cb5ab34a0e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| process.stdin.resume(); | |
| process.stdin.setEncoding('ascii'); | |
| var input_stdin = ""; | |
| var input_stdin_array = ""; | |
| var input_currentline = 0; | |
| process.stdin.on('data', function (data) { | |
| input_stdin += data; | |
| }); | |
| process.stdin.on('end', function () { | |
| input_stdin_array = input_stdin.split("\n"); | |
| main(); | |
| }); | |
| function readLine() { | |
| return input_stdin_array[input_currentline++]; | |
| } | |
| /////////////// ignore above this line //////////////////// | |
| function main() { | |
| var n = parseInt(readLine()); | |
| var contacts = ''; | |
| var result = ''; | |
| var indexTable = {}; | |
| for(var a0 = 0; a0 < n; a0++){ | |
| var op_temp = readLine().split(' '); | |
| var contact = op_temp[1]; | |
| if (op_temp[0] == 'add') { | |
| indexTable[contact[0]] = indexTable[contact[0]] || ''; | |
| indexTable[contact[0]] += ';' + contact; | |
| } else { | |
| var table = indexTable[contact[0]] || ''; | |
| result += table.split(';' + contact).length - 1 + '\n'; | |
| } | |
| } | |
| console.log(result); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment