-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.cpp
More file actions
76 lines (68 loc) · 2.23 KB
/
program.cpp
File metadata and controls
76 lines (68 loc) · 2.23 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
73
74
75
#include <stdio.h>
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;
void printDp(const std::vector<std::vector<bool>>& dp) {
for (int i = 0; i < dp.size(); ++i) {
for (int j = 0; j < dp[i].size(); ++j) {
std::cout << dp[i][j] << " ";
}
std::cout << std::endl;
}
std::cout << std::endl;
}
// Min Br
bool abbreviation(string a, string b) {
std::vector<std::vector<bool>> dp(a.size() + 1, std::vector<bool>(b.size() + 1, false));
dp[0][0] = true;
// init first row
for (int i = 1; i < dp[0].size(); ++i) {
dp[0][i] = false;
}
for (int i = 1; i < dp.size(); ++i) {
for (int j = 0; j < dp[0].size(); ++j) {
char lastA = a[i - 1]; // b
char lastB = j >= 1 ? b[j - 1] : ' '; // A
if (islower(lastA)) {
// del
if (dp[i - 1][j]) dp[i][j] = true;
}
// cast if needed
if (j >= 1 && toupper(lastA) == lastB) {
dp[i][j] = dp[i][j] || dp[i - 1][j - 1];
}
}
}
printDp(dp);
return dp[dp.size() - 1][dp[0].size() - 1];
}
int main(void) {
std::string s1 = "BFZZVHdQYHQEMNEFFRFJTQmNWHFVXRXlGTFNBqWQmyOWYWSTDSTMJRYHjBNTEWADLgHVgGIRGKFQSeCXNFNaIFAXOiQORUDROaNoJPXWZXIAABZKSZYFTDDTRGZXVZZNWNRHMvSTGEQCYAJSFvbqivjuqvuzafvwwifnrlcxgbjmigkms";
std::string s2 = "BFZZVHQYHQEMNEFFRFJTQNWHFVXRXGTFNBWQOWYWSTDSTMJRYHBNTEWADLHVGIRGKFQSCXNFNIFAXOQORUDRONJPXWZXIAABZKSZYFTDDTRGZXVZZNWNRHMSTGEQCYAJSF";
bool res = abbreviation(s1, s2);
std::cout << "res: " << std::boolalpha << res << std::endl;
return 0;
}
// Take string a and try to modif it into a string b, such that by capitalizing some a's letters
// Or can go to any letter of a, and delete all other lowercase letters in a
// If possible to first capitalize some of a's lower case letter, and delete all remaining lowecase -> becomes b
// AbcDE ABcDE ABDE
// ABDE
// AbcDE
// ADEF
// all the upper case in A -> preseved,
// optionally includeing some of orignal lwoer case
// lower case: Abc -> Ab; ABC
// a, b:
// AbD
// ABD
// "" A B D
// "" t f f f
// A f t f f
// b f t t f
// D f f f t
// beFgH
// EFH
// should be true