Skip to content

Commit

Permalink
Update AcWing 5280. 替换字符.md
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangguanghuib authored Oct 22, 2023
1 parent 3bfe7ff commit a9e8484
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions 周赛/Week126/AcWing 5280. 替换字符.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
https://www.acwing.com/problem/content/5283/ <br/>
<img width="703" alt="image" src="https://github.com/zhangguanghuib/acwing/assets/14832260/21ea4867-1748-45ea-9be4-1bb944cbf385">
```js
const readline = require('readline');

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

let inputs = [];
let n, m;
let s, t;
rl.on('line', function (line) {
inputs.push(line);
});

rl.on('close', function () {
[n, m] = inputs[0].split(' ').map(item => parseInt(item));
s = inputs[1];
t = inputs[2];
let res = new Array(n + 1);

for (k = 0; k < m - n + 1; k++) {
let p = calc(k);
if (p.length < res.length) {
res = p;
}
}
console.log(res.length);
if (res.length > 0) {
let str = res.map(item => item + 1).join(' ');
console.log(str);
}
});

function calc(k) {
let ret = [];
for (i = 0; i < n; ++i) {
if (s[i] !== t[i + k]) {
ret.push(i);
}
}
return ret;
}
```

0 comments on commit a9e8484

Please sign in to comment.