Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
gzshawnliang committed Aug 17, 2019
1 parent d0fe250 commit 5265530
Show file tree
Hide file tree
Showing 10 changed files with 322 additions and 1 deletion.
2 changes: 1 addition & 1 deletion myCpps/!-OJcreater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using namespace std;

//***************************************
const string CPPfile = "stringDistanceAndTransformProcess_UVA526"; //*
const string CPPfile = "palinwords_UVA257"; //*
//***************************************

ifstream fin(CPPfile + ".cpp");
Expand Down
83 changes: 83 additions & 0 deletions myCpps/palinwords_UVA257.cpp
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;
}
7 changes: 7 additions & 0 deletions myCpps/palinwords_UVA257.in
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
4 changes: 4 additions & 0 deletions myCpps/palinwords_UVA257.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MOEILIJKHEDEN
VERNEDEREN
AMAMA
MUMMUM
85 changes: 85 additions & 0 deletions myCpps/palinwords_UVA257OJ.cpp
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;
}

45 changes: 45 additions & 0 deletions myCpps/vacation_UVA10192.cpp
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;
}
7 changes: 7 additions & 0 deletions myCpps/vacation_UVA10192.in
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
#
3 changes: 3 additions & 0 deletions myCpps/vacation_UVA10192.out
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.
47 changes: 47 additions & 0 deletions myCpps/vacation_UVA10192OJ.cpp
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;
}

40 changes: 40 additions & 0 deletions other2/thomas/hash.cpp
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;
}

0 comments on commit 5265530

Please sign in to comment.