-
Notifications
You must be signed in to change notification settings - Fork 34
/
1159-Batman.cpp
71 lines (48 loc) · 1.01 KB
/
1159-Batman.cpp
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
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
int t;
int m;
int n;
int p;
char a[100];
char b[100];
char c[100];
int maxi;
int ans[100][100][100];
scanf("%d", &t);
for (int cs = 1; cs <= t; cs++) {
scanf("%s", a);
scanf("%s", b);
scanf("%s", c);
m = strlen(a);
n = strlen(b);
p = strlen(c);
for (int i = m; i >= 0; i--) {
for (int j = n; j >= 0; j--) {
for (int k = p; k >= 0; k--) {
if(i == m or j == n or k == p) {
ans[i][j][k] = 0;
continue;
}
if(a[i] == b[j] and b[j] == c[k]) {
ans[i][j][k] = 1 + ans[i+1][j+1][k+1];
continue;
}
maxi = -1;
maxi = max(ans[i+1][j][k], maxi);
maxi = max(ans[i][j+1][k], maxi);
maxi = max(ans[i][j][k+1], maxi);
maxi = max(ans[i+1][j+1][k], maxi);
maxi = max(ans[i+1][j][k+1], maxi);
maxi = max(ans[i][j+1][k+1], maxi);
ans[i][j][k] = maxi;
}
}
}
printf("Case %d: %d\n", cs, ans[0][0][0]);
}
}