-
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
518780d
commit 00dbef4
Showing
7 changed files
with
374 additions
and
62 deletions.
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,46 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("powerStrings_UVA10298.in"); | ||
ofstream fout("powerStrings_UVA10298.out"); | ||
|
||
int main() | ||
{ | ||
string s = "ercaabcabcjjjj", | ||
t = "abcabc"; | ||
|
||
int sizeS = s.size(), sizeT = t.size(); | ||
|
||
int _i = 0, _j = -1; | ||
vector<int> next(sizeT + 1, 0); next[0] = -1; | ||
while (_i <= sizeT - 1) | ||
{ | ||
while (_j >= 0 && t[_i] != t[_j]) | ||
{ | ||
_j = next[_j]; | ||
} | ||
|
||
++_i; ++_j; | ||
next[_i] = _j; | ||
} | ||
|
||
int i = 0, j = 0; | ||
vector<int> ans; | ||
while (i <= sizeS - 1) | ||
{ | ||
while (j >= 0 && s[i] != t[j]) | ||
{ | ||
j = next[j]; | ||
} | ||
|
||
++i; ++j; | ||
if (j == sizeT) | ||
{ | ||
ans.push_back(i - sizeT); | ||
j = next[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,166 @@ | ||
#include <algorithm> | ||
#include <cmath> | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <fstream> | ||
#include <iomanip> | ||
#include <iostream> | ||
#include <set> | ||
#include <string> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
//*************************************** | ||
const string CPPfile = "secretWord_UVA12467"; //* | ||
//*************************************** | ||
|
||
ifstream fin(CPPfile + ".cpp"); | ||
ofstream fout(CPPfile + "OJ.cpp"); | ||
|
||
bool _isAlpha(char a) | ||
{ | ||
return (a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z'); | ||
} | ||
|
||
int main() | ||
{ | ||
bool findMain = false; | ||
bool fastDone = false; | ||
while (true) | ||
{ | ||
string in = "I am Shawn."; | ||
getline(fin, in); | ||
int size = in.size(); | ||
|
||
if (findMain == true && fastDone == false) | ||
{ | ||
fout << in << '\n'; | ||
fout << "\tios_base::sync_with_stdio(false);\n\tstd::cin.tie(NULL);\n"; | ||
fastDone = true; | ||
continue; | ||
} | ||
|
||
if (in == "I am Shawn.") | ||
{ | ||
break; | ||
} | ||
else if (in == "") | ||
{ | ||
fout << '\n'; | ||
continue; | ||
} | ||
else if (in == "int main()") | ||
{ | ||
findMain = true; | ||
fout << "int main()\n"; | ||
continue; | ||
} | ||
else if (size >= 9) | ||
{ | ||
int i = 0, SPACEcount = 0, TABcount = 0; | ||
while (in[i] == ' ' || in[i] == '\t') | ||
{ | ||
++i; | ||
if (in[i] == ' ') | ||
{ | ||
++SPACEcount; | ||
} | ||
else | ||
{ | ||
++TABcount; | ||
} | ||
} | ||
|
||
string front = ""; | ||
for (int j = i; j <= size - 1; ++j) | ||
{ | ||
front.push_back(in[j]); | ||
} | ||
|
||
if (front == "return 0;") | ||
{ | ||
for (int c = 1; c <= SPACEcount; ++c) | ||
{ | ||
fout << ' '; | ||
} | ||
for (int c = 1; c <= TABcount; ++c) | ||
{ | ||
fout << '\t'; | ||
} | ||
|
||
fout << "cout.flush();\n"; | ||
|
||
for (int c = 1; c <= SPACEcount; ++c) | ||
{ | ||
fout << ' '; | ||
} | ||
for (int c = 1; c <= TABcount; ++c) | ||
{ | ||
fout << '\t'; | ||
} | ||
|
||
fout << "return 0;\n"; | ||
continue; | ||
} | ||
} | ||
|
||
if (size >= 8) | ||
{ | ||
string front = ""; | ||
|
||
int i = 0; | ||
while (in[i] == ' ' || in[i] == '\t') | ||
{ | ||
++i; | ||
} | ||
|
||
front.push_back(in[i]); | ||
front.push_back(in[i + 1]); | ||
front.push_back(in[i + 2]); | ||
front.push_back(in[i + 3]); | ||
front.push_back(in[i + 4]); | ||
front.push_back(in[i + 5]); | ||
front.push_back(in[i + 6]); | ||
front.push_back(in[i + 7]); | ||
|
||
if (front == "ifstream" || front == "ofstream") | ||
{ | ||
continue; | ||
} | ||
} | ||
if (size >= 2) | ||
{ | ||
int i = 0; | ||
while (in[i] == ' ' || in[i] == '\t') | ||
{ | ||
++i; | ||
} | ||
|
||
if (i <= size - 2) | ||
{ | ||
if (in[i] == '/' && in[i + 1] == '/') | ||
{ | ||
continue; | ||
} | ||
} | ||
} | ||
if (size > 2) | ||
|
||
for (int i = 0; i <= size - 5; ++i) | ||
{ | ||
string temp; | ||
temp.push_back(in[i]); | ||
temp.push_back(in[i + 1]); | ||
temp.push_back(in[i + 2]); | ||
if ((temp == "fin" && _isAlpha(in[i + 3]) == false) || (temp == "fou" && in[i + 3] == 't' && _isAlpha(in[i + 4]) == false)) | ||
{ | ||
in[i] = 'c'; | ||
} | ||
} | ||
|
||
fout << in << '\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,71 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("secretWord_UVA12467.in"); | ||
ofstream fout("secretWord_UVA12467.out"); | ||
|
||
int main() | ||
{ | ||
int tcc; fin >> tcc; | ||
for (int c = 1; c <= tcc; ++c) | ||
{ | ||
string s; fin >> s; | ||
int sizeS = s.size(); | ||
|
||
int l = 1, r = sizeS; | ||
while (l <= r) | ||
{ | ||
int m = (l + r) / 2; | ||
|
||
string t = s.substr(0, m); reverse(t.begin(), t.end()); | ||
|
||
int _i = 0, _j = -1; | ||
vector<int> next(m + 1, 0); next[0] = -1; | ||
while (_i <= m - 1) | ||
{ | ||
while (_j >= 0 && t[_i] != t[_j]) | ||
{ | ||
_j = next[_j]; | ||
} | ||
|
||
++_i; ++_j; | ||
next[_i] = _j; | ||
} | ||
|
||
|
||
bool flag = false; | ||
int i = 0, j = 0; | ||
while (i <= sizeS - 1) | ||
{ | ||
while (j >= 0 && s[i] != t[j]) | ||
{ | ||
j = next[j]; | ||
} | ||
|
||
++i; ++j; | ||
if (j == m) | ||
{ | ||
flag = true; | ||
j = next[j]; | ||
|
||
break; | ||
} | ||
} | ||
|
||
if (flag == true) | ||
{ | ||
l = m + 1; | ||
} | ||
else | ||
{ | ||
r = m - 1; | ||
} | ||
} | ||
|
||
string t = s.substr(0, r); reverse(t.begin(), t.end()); | ||
fout << t << '\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,2 @@ | ||
1 | ||
listentonetsilthesilence |
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 @@ | ||
netsil |
Oops, something went wrong.