Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 392d437

Browse files
beautiful-pairs
1 parent fec5fb9 commit 392d437

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

‎beautiful-pairs.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /