-
Notifications
You must be signed in to change notification settings - Fork 21
/
f.js
29 lines (21 loc) · 823 Bytes
/
f.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Не проходит лимит по времени на 66 тесте, но дело не в решении, а в js
const readline = require('readline');
const customers = {}
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', (data) => {
const [customer, item, quantity] = data.split(' ')
if (!customers[customer])
customers[customer] = {}
if (!customers[customer][item])
customers[customer][item] = 0
customers[customer][item] += +quantity
});
rl.on('close', () => {
Object.keys(customers).sort().forEach(customer => {
console.log(`${customer}:`)
const items = customers[customer]
Object.keys(items).sort().forEach(item => {
console.log(`${item} ${items[item]}`)
})
})
});