Untitled
unknown
plain_text
2 years ago
1.1 kB
4
Indexable
function countWords(sentence, n, words) { let map1 = new Map(); for (let i = 0; i < n; i++) { // if (!map1.has(words[i])) { map1.set(words[i], 1); // } } //iterating let i = 0; let j = 0; let count = 0; while (j < sentence.length) { let temp = ""; if (!(sentence.charCodeAt(j) === 32)) { j++; } else if (j === sentence.length - 1) { temp = sentence.substring(i, j + 1); if (map1.has(temp)) { count++; map1.delete(temp); } } else { temp = sentence.substring(i, j) j++; i = j; if (map1.has(temp)) { count++; map1.delete(temp); } } } return count; } function main() { let sentence = readLine(); let n = parseInt(readLine()); let temp = readLine(); let words = temp.split(' '); let res = countWords(sentence, n, words); console.log(res); }
Editor is loading...