-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0fe250
commit 5265530
Showing
10 changed files
with
322 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("palinwords_UVA257.in"); | ||
ofstream fout("palinwords_UVA257.out"); | ||
|
||
bool isPalindrome(string & s) | ||
{ | ||
int n = s.size(); | ||
for (int l = 0, r = n - 1; l <= r; ++l, --r) | ||
{ | ||
if (s[l] != s[r]) return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool isSame(string & a, string & b) | ||
{ | ||
int sizeA = a.size(), sizeB = b.size(); | ||
if (sizeA < sizeB) | ||
{ | ||
for (int i = 0; i + sizeA - 1 <= sizeB - 1; ++i) | ||
{ | ||
if (a == b.substr(i, sizeA)) return true; | ||
} | ||
return false; | ||
} | ||
else | ||
{ | ||
for (int i = 0; i + sizeB - 1 <= sizeA - 1; ++i) | ||
{ | ||
if (b == a.substr(i, sizeB)) return true; | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
while (true) | ||
{ | ||
string s = ""; fin >> s; | ||
if (s == "") break; | ||
|
||
int n = s.size(); | ||
set<string> p_s; | ||
for (int i = 0; i <= n - 1; ++i) | ||
{ | ||
for (int len = 3; i + len - 1 <= n - 1 && len <= 4; ++len) | ||
{ | ||
string now = s.substr(i, len); | ||
if (isPalindrome(now) == true) p_s.insert(now); | ||
} | ||
} | ||
|
||
vector<string> p; | ||
for (auto it = p_s.begin(); it != p_s.end(); ++it) | ||
{ | ||
p.push_back(*it); | ||
} | ||
|
||
bool isPalinword = false; | ||
int size = p.size(); | ||
for (int i = 0; i <= size - 1 && isPalinword == false; ++i) | ||
{ | ||
for (int j = i + 1; j <= size - 1 && isPalinword == false; ++j) | ||
{ | ||
if (isSame(p[i], p[j]) == false) | ||
{ | ||
isPalinword = true; | ||
} | ||
} | ||
} | ||
|
||
if (isPalinword == true) | ||
{ | ||
fout << s << '\n'; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
MOEILIJKHEDEN INVOER | ||
VERNEDEREN | ||
AMUMA AMAMA MUMMUM | ||
AMATRAMA AAAA | ||
ABATRABAR | ||
DUMMY | ||
WORDS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
MOEILIJKHEDEN | ||
VERNEDEREN | ||
AMAMA | ||
MUMMUM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
|
||
bool isPalindrome(string & s) | ||
{ | ||
int n = s.size(); | ||
for (int l = 0, r = n - 1; l <= r; ++l, --r) | ||
{ | ||
if (s[l] != s[r]) return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool isSame(string & a, string & b) | ||
{ | ||
int sizeA = a.size(), sizeB = b.size(); | ||
if (sizeA < sizeB) | ||
{ | ||
for (int i = 0; i + sizeA - 1 <= sizeB - 1; ++i) | ||
{ | ||
if (a == b.substr(i, sizeA)) return true; | ||
} | ||
return false; | ||
} | ||
else | ||
{ | ||
for (int i = 0; i + sizeB - 1 <= sizeA - 1; ++i) | ||
{ | ||
if (b == a.substr(i, sizeB)) return true; | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); | ||
std::cin.tie(NULL); | ||
while (true) | ||
{ | ||
string s = ""; cin >> s; | ||
if (s == "") break; | ||
|
||
int n = s.size(); | ||
set<string> p_s; | ||
for (int i = 0; i <= n - 1; ++i) | ||
{ | ||
for (int len = 3; i + len - 1 <= n - 1 && len <= 4; ++len) | ||
{ | ||
string now = s.substr(i, len); | ||
if (isPalindrome(now) == true) p_s.insert(now); | ||
} | ||
} | ||
|
||
vector<string> p; | ||
for (auto it = p_s.begin(); it != p_s.end(); ++it) | ||
{ | ||
p.push_back(*it); | ||
} | ||
|
||
bool isPalinword = false; | ||
int size = p.size(); | ||
for (int i = 0; i <= size - 1 && isPalinword == false; ++i) | ||
{ | ||
for (int j = i + 1; j <= size - 1 && isPalinword == false; ++j) | ||
{ | ||
if (isSame(p[i], p[j]) == false) | ||
{ | ||
isPalinword = true; | ||
} | ||
} | ||
} | ||
|
||
if (isPalinword == true) | ||
{ | ||
cout << s << '\n'; | ||
} | ||
} | ||
|
||
cout.flush(); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("vacation_UVA10192.in"); | ||
ofstream fout("vacation_UVA10192.out"); | ||
|
||
int main() | ||
{ | ||
int t = 0; | ||
while (true) | ||
{ | ||
string a = "#"; | ||
getline(fin, a); | ||
if (a == "#") break; | ||
|
||
++t; | ||
|
||
string b; getline(fin, b); | ||
|
||
a = ' ' + a; | ||
b = ' ' + b; | ||
|
||
int na = a.size() - 1, nb = b.size() - 1; | ||
vector<vector<int>> dp(na + 1, vector<int>(nb + 1, 0)); | ||
for (int i = 1; i <= na; ++i) | ||
{ | ||
for (int j = 1; j <= nb; ++j) | ||
{ | ||
if (a[i] == b[j]) | ||
{ | ||
dp[i][j] = dp[i - 1][j - 1] + 1; | ||
} | ||
else | ||
{ | ||
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); | ||
} | ||
} | ||
} | ||
|
||
fout << "Case #" << t << ": you can visit at most " << dp[na][nb] << " cities.\n"; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
gvwnrgibubvr | ||
as ngbb+v | ||
rewibv vnwso | ||
s aghovnswpog | ||
)^(*$@()%5709&(%*#5gasdg | ||
__^+(#)%34596075^*340%*5absdffgh439063 | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Case #1: you can visit at most 5 cities. | ||
Case #2: you can visit at most 5 cities. | ||
Case #3: you can visit at most 14 cities. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); | ||
std::cin.tie(NULL); | ||
int t = 0; | ||
while (true) | ||
{ | ||
string a = "#"; | ||
getline(cin, a); | ||
if (a == "#") break; | ||
|
||
++t; | ||
|
||
string b; getline(cin, b); | ||
|
||
a = ' ' + a; | ||
b = ' ' + b; | ||
|
||
int na = a.size() - 1, nb = b.size() - 1; | ||
vector<vector<int>> dp(na + 1, vector<int>(nb + 1, 0)); | ||
for (int i = 1; i <= na; ++i) | ||
{ | ||
for (int j = 1; j <= nb; ++j) | ||
{ | ||
if (a[i] == b[j]) | ||
{ | ||
dp[i][j] = dp[i - 1][j - 1] + 1; | ||
} | ||
else | ||
{ | ||
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); | ||
} | ||
} | ||
} | ||
|
||
cout << "Case #" << t << ": you can visit at most " << dp[na][nb] << " cities.\n"; | ||
} | ||
|
||
cout.flush(); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
//ifstream fin("hash.in"); | ||
//ofstream fout("hash.out"); | ||
|
||
int myhash(int x) {return x % 5;} | ||
|
||
int myhash2(string x, int prime) | ||
{ | ||
int hashValue = 0; | ||
for (auto i : x) | ||
hashValue += i; | ||
return hashValue % prime; | ||
} | ||
|
||
int main() | ||
{ | ||
cout << myhash(13) << '\n'; | ||
cout << myhash(7) << '\n'; | ||
cout << myhash(14) << '\n'; | ||
cout << myhash(11) << '\n'; | ||
|
||
cout << "----------------" << "\n"; | ||
cout << myhash2("abc",11) << '\n'; | ||
cout << myhash2("abe",11) << '\n'; | ||
cout << myhash2("abg",11) << '\n'; | ||
cout << myhash2("gbc",11) << '\n'; | ||
cout << "----------------" << "\n"; | ||
|
||
std::hash<string> h; | ||
cout << h("abe") <<'\n'; | ||
cout << h("abc") <<'\n'; | ||
|
||
cout << h("Meet the new boss...") <<'\n'; | ||
|
||
|
||
return 0; | ||
} |