generated from DavidWesley/clean-node-ts-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2549.ts
31 lines (24 loc) · 973 Bytes
/
2549.ts
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
30
31
import { readFileSync } from "node:fs"
import { EOL } from "node:os"
import { stdin } from "node:process"
const input = readFileSync(stdin.fd, { encoding: "utf8" })
.split(EOL)
.map((line) => line.trim())
const createStudentUsername = (name: string, year: number): string =>
name
.replace(/(\b\w)\w+/g, "$1")
.replace(/\s+/g, "")
.concat(year.toString())
function main(): void {
const output: Array<number> = []
for (let [i, N, A] = [0, 0, 0]; i < input.length; i += N + 1) {
if (input[i] === "") break
;[N = 0, A = 0] = (input.at(i) ?? "0 0").split(" ", 2).map((value) => Number.parseInt(value, 10))
const usernames: string[] = Array.from({ length: N }, (_, j: number) => createStudentUsername(input.at(i + 1 + j)!, A))
const uniqueUsernames = new Set(usernames)
const nonStandardNamesQuantity = usernames.length - uniqueUsernames.size
output.push(nonStandardNamesQuantity)
}
console.log(output.join(EOL))
}
main()