|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const fs = require('fs'); |
| 4 | + |
| 5 | +process.stdin.resume(); |
| 6 | +process.stdin.setEncoding('utf-8'); |
| 7 | + |
| 8 | +let inputString = ''; |
| 9 | +let currentLine = 0; |
| 10 | + |
| 11 | +process.stdin.on('data', inputStdin => { |
| 12 | + inputString += inputStdin; |
| 13 | +}); |
| 14 | + |
| 15 | +process.stdin.on('end', _ => { |
| 16 | + inputString = inputString.replace(/\s*$/, '') |
| 17 | + .split('\n') |
| 18 | + .map(str => str.replace(/\s*$/, '')); |
| 19 | + |
| 20 | + main(); |
| 21 | +}); |
| 22 | + |
| 23 | +function readLine() { |
| 24 | + return inputString[currentLine++]; |
| 25 | +} |
| 26 | + |
| 27 | +function del(array, item) { |
| 28 | + const index = array.indexOf(item); |
| 29 | + if (index > -1) { |
| 30 | + array.splice(index, 1); |
| 31 | + } |
| 32 | + return array; |
| 33 | +} |
| 34 | +// Complete the beautifulPairs function below. |
| 35 | +function beautifulPairs(A, B) { |
| 36 | + B.forEach(x => del(A,x)); |
| 37 | + if(A.length === 1) return B.length; |
| 38 | + else if(A.length === 0) return B.length -1; |
| 39 | + else return (B.length - A.length) +1; |
| 40 | +} |
| 41 | + |
| 42 | +function main() { |
| 43 | + const ws = fs.createWriteStream(process.env.OUTPUT_PATH); |
| 44 | + |
| 45 | + const n = parseInt(readLine(), 10); |
| 46 | + |
| 47 | + const A = readLine().split(' ').map(ATemp => parseInt(ATemp, 10)); |
| 48 | + |
| 49 | + const B = readLine().split(' ').map(BTemp => parseInt(BTemp, 10)); |
| 50 | + |
| 51 | + let result = beautifulPairs(A, B); |
| 52 | + |
| 53 | + ws.write(result + "\n"); |
| 54 | + |
| 55 | + ws.end(); |
| 56 | +} |
0 commit comments