| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- const fs = require('fs');
- const readline = require('readline');
- function isMarker(str) {
- let tmp = [];
- return !str.split("").some(i => {
- if (tmp.includes(i))
- return true;
- tmp.push(i);
- return false;
- });
- }
- function findMarker(input, len) {
- for (let i =0; i < input.length -len; ++i) {
- if (isMarker(input.substring(i, i+len))) {
- return i;
- }
- }
- }
- function strLine(line) {
- let output = "";
- let pos14 = -1;
- let pos4 = -1;
- while (line.length) {
- if (pos14 < 0)
- pos14 = findMarker(line, 14);
- if (pos4 < 0)
- pos4 = findMarker(line, 4);
- if (pos14 < 4) {
- output += line.substring(0, pos14) + '\033[34;1m' + line.substring(pos4, pos4 +14) +'\033[39;00m';
- line = line.substring(14);
- pos14 = pos4 = -1;
- } else if (pos4 === 0) {
- output += '\033[95;1m' + line.substring(0, 4) +'\033[39;00m';
- line = line.substring(4);
- pos4 = -1;
- pos14 -= 4;
- if (pos14 === 0) pos14 = -1;
- } else {
- if (pos14 <= pos4) {
- output += line.substring(0, pos14);
- line = line.substring(pos14);
- pos4 -= pos14;
- if (pos4 === 0) pos4 = -1;
- pos14 = 0;
- } else if (pos4) {
- output += line.substring(0, pos4);
- line = line.substring(pos4);
- pos14 -= pos4;
- if (pos14 === 0) pos14 = -1;
- pos4 = 0;
- } else {
- output += line;
- line = "";
- }
- }
- }
- return output;
- }
- async function main() {
- for await (let line of readline.createInterface({ input: process.stdin })) {
- console.log(strLine(line));
- console.log("Position of distinct 4 chars: " + (findMarker(line, 4)+4));
- console.log("Position of distinct 14 chars: " + (findMarker(line, 14)+14));
- break;
- }
- };
- (main());
|