Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
gzshawnliang committed Sep 7, 2019
1 parent da8138c commit e45af25
Show file tree
Hide file tree
Showing 9 changed files with 232 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 = "freeParentheses_UVA1238"; //*
const string CPPfile = "extendtoPalindromes_UVA11475"; //*
//***************************************

ifstream fin(CPPfile + ".cpp");
Expand Down
61 changes: 61 additions & 0 deletions myCpps/extendtoPalindromes_UVA11475.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <bits/stdc++.h>

using namespace std;

ifstream fin("extendtoPalindromes_UVA11475.in");
ofstream fout("extendtoPalindromes_UVA11475.out");

const int N = 52;

int turn(char ch)
{
if ('a' <= ch && ch <= 'z') return ch - 'a';
else return ch - 'A' + 26;
}

bool sovle(int i, string & s)
{
int k = s.size() - 2;
for (int j = i + 1; j <= k; ++j, --k)
{
if (s[j] != s[k])
{
return false;
}
}

return true;
}

int main()
{
while (true)
{
string s = ""; fin >> s;
if (s == "") break;

int size = s.size();
vector<vector<int>> a(N);
for (int i = 0; i <= size - 1; ++i)
{
a[turn(s[i])].push_back(i);
}

int size_a_back = a[turn(s[size - 1])].size(), ans = -1;
for (int p = 0; p <= size_a_back - 1; ++p)
{
int i = a[turn(s[size - 1])][p]; ans = i;

if (sovle(i, s) == true)
{
break;
}
}

string temp = s.substr(0, ans); reverse(temp.begin(), temp.end());

fout << s + temp << '\n';
}

return 0;
}
4 changes: 4 additions & 0 deletions myCpps/extendtoPalindromes_UVA11475.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
caffeines
happycoding
solveAsMuchAsYouCan
abAaaba
4 changes: 4 additions & 0 deletions myCpps/extendtoPalindromes_UVA11475.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
caffeinesenieffac
happycodingnidocyppah
solveAsMuchAsYouCanaCuoYsAhcuMsAevlos
abAaabaaAba
63 changes: 63 additions & 0 deletions myCpps/extendtoPalindromes_UVA11475OJ.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <bits/stdc++.h>

using namespace std;


const int N = 52;

int turn(char ch)
{
if ('a' <= ch && ch <= 'z') return ch - 'a';
else return ch - 'A' + 26;
}

bool sovle(int i, string & s)
{
int k = s.size() - 2;
for (int j = i + 1; j <= k; ++j, --k)
{
if (s[j] != s[k])
{
return false;
}
}

return true;
}

int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
while (true)
{
string s = ""; cin >> s;
if (s == "") break;

int size = s.size();
vector<vector<int>> a(N);
for (int i = 0; i <= size - 1; ++i)
{
a[turn(s[i])].push_back(i);
}

int size_a_back = a[turn(s[size - 1])].size(), ans = -1;
for (int p = 0; p <= size_a_back - 1; ++p)
{
int i = a[turn(s[size - 1])][p]; ans = i;

if (sovle(i, s) == true)
{
break;
}
}

string temp = s.substr(0, ans); reverse(temp.begin(), temp.end());

cout << s + temp << '\n';
}

cout.flush();
return 0;
}

80 changes: 80 additions & 0 deletions myCpps/kmp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include <bits/stdc++.h>

using namespace std;

ifstream fin("powerStrings_UVA10298.in");
ofstream fout("powerStrings_UVA10298.out");

vector<int> createNext(string & P)
{
vector<int> next;
return next;
}

vector<int> KmpSearch(string & T,string & P)
{
vector<int> pos;
vector<int> next = createNext(P);

//begin search

return pos;
}

int main()
{
string s = "ababababababababcabababab",
t = "abababc";

int sizeS = s.size(), sizeT = t.size();

int _i = 1, _j = 0;
vector<int> next(sizeT, 0); next[0] = 0;
while (_i <= sizeT - 1)
{
while (_j > 0 && t[_i] != t[_j])
{
if (_j > 0) _j = next[_j - 1];

if (_j == -1) break;
}

if (t[_i] == t[_j]) next[_i] = _j + 1;

++_i;
++_j;
}

int i = 0, j = 0;
vector<int> ans;
while (i <= sizeS - 1)
{
if (s[i] != t[j])
{
if (j == 0)
{
++i;
}
else
{
j = next[j - 1];
}
}
else
{
if (j == sizeT - 1)
{
ans.push_back(i - sizeT + 1);
++i;
j = 0;
}
else
{
++i;
++j;
}
}
}

return 0;
}
19 changes: 19 additions & 0 deletions myCpps/powerStrings_UVA10298.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <bits/stdc++.h>

using namespace std;

ifstream fin("powerStrings_UVA10298.in");
ofstream fout("powerStrings_UVA10298.out");



int main()
{
while (true)
{
string s = ""; fin >> s;
if (s == "") break;
}

return 0;
}
Empty file added myCpps/powerStrings_UVA10298.in
Empty file.
Empty file.

0 comments on commit e45af25

Please sign in to comment.