forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC.cpp
More file actions
63 lines (53 loc) · 1010 Bytes
/
Copy pathC.cpp
File metadata and controls
63 lines (53 loc) · 1010 Bytes
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
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;
#define LEN 19
#define MOD 10000
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
string str;
string text = "welcome to code jam";
int mm[25][505];
int len;
int dp(int now, int idx) {
int& ret = mm[now][idx];
if (ret != -1) return ret;
if (now == LEN) {
return ret = 1;
}
ret = 0;
FOR(i,idx+1,len-1) {
if (str[i] != text[now]) continue;
ret = (ret + dp(now + 1, i)) % MOD;
}
return ret;
}
void run() {
getline(cin, str);
len = str.length();
memset(mm, -1, sizeof(mm));
int res = 0;
REP(i,len) {
if (str[i] == text[0]) {
res = (res + dp(1, i)) % MOD;
}
}
if (res <= 9) cout << "000";
else if (res <= 99) cout << "00";
else if (res <= 999) cout << "0";
cout << res << endl;
}
int main() {
int n;
cin >> n;
getline(cin, str);
REP(k,n) {
cout << "Case #" << k + 1 << ": ";
run();
}
return 0;
}