-
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
da8138c
commit e45af25
Showing
9 changed files
with
232 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,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; | ||
} |
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 @@ | ||
caffeines | ||
happycoding | ||
solveAsMuchAsYouCan | ||
abAaaba |
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 @@ | ||
caffeinesenieffac | ||
happycodingnidocyppah | ||
solveAsMuchAsYouCanaCuoYsAhcuMsAevlos | ||
abAaabaaAba |
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,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; | ||
} | ||
|
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,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; | ||
} |
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,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.
Empty file.