# 47. 拼接URL

47

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});
rl.on('line', function(line) {
    const split = line.split(',');
    if (split.length ===0) {
        console.log('/');
        return;
    }
    const prefix = split[0];
    let suffix = split[1];
    const preHas = prefix.endsWith('/');
    const sufHas = suffix.startsWith('/');
    const url = [];
    url.push(prefix);
    if (!preHas && !sufHas) {
        url.push('/');
    }
    if (preHas && sufHas) {
        suffix = suffix.slice(1);
    }
    url.push(suffix);
    const url = url.join('');
    console.log(url);
});
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