-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsubsequence.js
More file actions
executable file
·72 lines (62 loc) · 1.36 KB
/
Copy pathsubsequence.js
File metadata and controls
executable file
·72 lines (62 loc) · 1.36 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// run by node subsequence.js < subsequence.txt
var pattern = "welcome to code jam";
function count(s, p) {
var table = [];
for (var j = 0; j < p.length; j++) {
table[j] = 0;
}
for (var i = 0; i < s.length; i++) {
for (var j = 0; j < p.length; j++) {
if (s.charAt(i) == p.charAt(j)) {
if (j == 0) {
table[j]++;
} else {
table[j] += table[j-1];
}
table[j] %= 10000;
}
}
}
return table[p.length-1];
}
function parse(data) {
var lines = data.split("\n");
var T = parseInt(lines[0]);
for (var i = 1; i <= T; i++) {
var result = count(lines[i], pattern);
var info = result % 10000;
if (result < 10) info = "000" + result; else
if (result < 100) info = "00" + result; else
if (result < 1000) info = "0" + result;
console.log("Case #" + i + ": " + info);
}
}
function main() {
var process = require("process");
process.stdin.setEncoding('utf8');
var buffer = "";
process.stdin.on("readable", function() {
var chunk = process.stdin.read();
buffer += chunk == null ? "" : chunk;
});
process.stdin.on("end", function() {
parse(buffer);
});
}
main();
// console.log(count("wweell", "wel"));
/*
w w e e l l c c o o m m e e
w 1 2 2 2 2 2 2 2 2 2 2 2 2 2
e 0 0 2 4 4 4 4 4 4 4 4 4 6 8
l 0 0 0 0 4 8 8 8 8 8 8 8 8 8
c 0 0 0 0 0 0 8
o
m
e
*/
/*
var s = "";
s = "wweellccoommee to code qps jam";
// s = "welcome to code jam";
*/