-
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
15c1edd
commit 95a41fe
Showing
24 changed files
with
981 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,6 @@ | |
*.exe | ||
*.out | ||
*.app | ||
|
||
bin/ | ||
|
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,34 @@ | ||
#include <algorithm> | ||
#include <iostream> | ||
#include <vector> | ||
#include <utility> | ||
|
||
using namespace std; | ||
|
||
typedef pair<string, string> ps; | ||
|
||
int main() { | ||
ios::sync_with_stdio(false); | ||
vector<ps> w; | ||
for (string s; cin >> s && s != "#"; ) { | ||
string ss = s; | ||
transform(ss.begin(), ss.end(), ss.begin(), ::tolower); | ||
sort(ss.begin(), ss.end()); | ||
w.emplace_back(ss, s); | ||
} | ||
sort(w.begin(), w.end(), | ||
[] (const ps& e1, const ps& e2) { return e1.first < e2.first; }); | ||
int l = w.size() - 1; | ||
vector<string> r; | ||
for (int i = 0; i <= l; i++) { | ||
if ((i == 0 || w[i].first != w[i - 1].first) | ||
&& (i == l || w[i].first != w[i + 1].first)) { | ||
r.push_back(w[i].second); | ||
} | ||
} | ||
sort(r.begin(), r.end()); | ||
for (const string& s : r) { | ||
cout << s << endl; | ||
} | ||
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,59 @@ | ||
#include <iostream> | ||
#include <cstring> | ||
|
||
using namespace std; | ||
|
||
int cm[256]; | ||
|
||
int main() { | ||
ios::sync_with_stdio(false); | ||
memset(cm, 0, sizeof cm); | ||
cm['A'] = 'A'; | ||
cm['E'] = '3'; | ||
cm['H'] = 'H'; | ||
cm['I'] = 'I'; | ||
cm['J'] = 'L'; | ||
cm['L'] = 'J'; | ||
cm['M'] = 'M'; | ||
cm['S'] = '2'; | ||
cm['T'] = 'T'; | ||
cm['U'] = 'U'; | ||
cm['V'] = 'V'; | ||
cm['W'] = 'W'; | ||
cm['X'] = 'X'; | ||
cm['Y'] = 'Y'; | ||
cm['Z'] = '5'; | ||
cm['O'] = 'O'; | ||
cm['1'] = '1'; | ||
cm['2'] = 'S'; | ||
cm['3'] = 'E'; | ||
cm['5'] = 'Z'; | ||
cm['8'] = '8'; | ||
string s; | ||
while (cin >> s) { | ||
bool p = true, m = true; | ||
auto left = s.begin(); | ||
auto right = s.end() - 1; | ||
while (left <= right && (p || m)) { | ||
if (*left != *right) { | ||
p = false; | ||
} | ||
if (cm[*left] != *right) { | ||
m = false; | ||
} | ||
++left; | ||
--right; | ||
} | ||
cout << s; | ||
if (p && m) { | ||
cout << " -- is a mirrored palindrome."; | ||
} else if (p) { | ||
cout << " -- is a regular palindrome."; | ||
} else if (m) { | ||
cout << " -- is a mirrored string."; | ||
} else { | ||
cout << " -- is not a palindrome."; | ||
} | ||
cout << endl << endl; | ||
} | ||
} |
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,38 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int k, x[12], i[6]; | ||
|
||
#define FOR(x, s) for (x = s; x < k; x++) | ||
|
||
int main() { | ||
bool first = true; | ||
ios::sync_with_stdio(false); | ||
while (cin >> k && k) { | ||
for (int i = 0; i < k; i++) { | ||
cin >> x[i]; | ||
} | ||
if (!first) { | ||
cout << endl; | ||
} | ||
first = false; | ||
FOR(i[0], 0) { | ||
FOR(i[1], i[0] + 1) { | ||
FOR(i[2], i[1] + 1) { | ||
FOR(i[3], i[2] + 1) { | ||
FOR(i[4], i[3] + 1) { | ||
FOR(i[5], i[4] + 1) { | ||
for (int j = 0; j < 5; j++) { | ||
cout << x[i[j]] << ' '; | ||
} | ||
cout << x[i[5]] << endl; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
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,53 @@ | ||
#include <iostream> | ||
#include <cstring> | ||
|
||
using namespace std; | ||
|
||
int primes[11] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 }; | ||
bool is_prime[32]; | ||
|
||
int n, p[17], r[17]; | ||
|
||
void place(int k) { | ||
if (k > n) { | ||
if (!is_prime[r[1] + r[n]]) { | ||
return; | ||
} | ||
for (int i = 1; i <= n; i++) { | ||
if (i > 1) { | ||
cout << ' '; | ||
} | ||
cout << r[i]; | ||
} | ||
cout << endl; | ||
return; | ||
} | ||
for (int i = 2; i <= n; i++) { | ||
if (p[i] == 0 && is_prime[i + r[k - 1]]) { | ||
r[k] = i; | ||
p[i] = k; | ||
place(k + 1); | ||
p[i] = 0; | ||
} | ||
} | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false); | ||
memset(is_prime, 0, sizeof is_prime); | ||
for (int i = 0; i < 11; i++) { | ||
is_prime[primes[i]] = true; | ||
} | ||
for (int c = 1; cin >> n; c++) { | ||
memset(p, 0, sizeof p); | ||
memset(r, 0, sizeof r); | ||
p[1] = 1; | ||
r[1] = 1; | ||
if (c > 1) { | ||
cout << endl; | ||
} | ||
cout << "Case " << c << ':' << endl; | ||
place(2); | ||
} | ||
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,49 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int t, n, x[12], r[12]; | ||
|
||
bool found; | ||
|
||
void sum(int i, int l, int s) { | ||
if (s > t) { | ||
return; | ||
} | ||
if (s == t) { | ||
for (int j = 0; j < l; j++) { | ||
if (j > 0) { | ||
cout << '+'; | ||
} | ||
cout << r[j]; | ||
} | ||
cout << endl; | ||
found = true; | ||
return; | ||
} | ||
if (i == n) { | ||
return; | ||
} | ||
r[l] = x[i]; | ||
sum(i + 1, l + 1, s + x[i]); | ||
while (i + 1 < n && x[i + 1] == x[i]) { | ||
i++; | ||
} | ||
sum(i + 1, l, s); | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false); | ||
while (cin >> t >> n && t && n) { | ||
for (int i = 0; i < n; i++) { | ||
cin >> x[i]; | ||
} | ||
found = false; | ||
cout << "Sums of " << t << ':' << endl; | ||
sum(0, 0, 0); | ||
if (!found) { | ||
cout << "NONE" << endl; | ||
} | ||
} | ||
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,38 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int l[20]; | ||
|
||
int main() { | ||
ios::sync_with_stdio(false); | ||
for (int n, m; cin >> n >> m; ) { | ||
for (int i = 0; i < m; i++) { | ||
cin >> l[i]; | ||
} | ||
int r, max_s = 0; | ||
int b = 1 << m; | ||
for (int i = 0; i < b; i++) { | ||
int s = 0; | ||
for (int j = 0; j < m; j++) { | ||
if (i & (1 << j)) { | ||
s += l[j]; | ||
} | ||
} | ||
if (s > n) { | ||
continue; | ||
} | ||
if (s > max_s) { | ||
r = i; | ||
max_s = s; | ||
} | ||
} | ||
for (int i = 0; i < m; i++) { | ||
if (r & (1 << i)) { | ||
cout << l[i] << ' '; | ||
} | ||
} | ||
cout << "sum:" << max_s << endl; | ||
} | ||
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,60 @@ | ||
#include <iostream> | ||
#include <iomanip> | ||
#include <bitset> | ||
|
||
using namespace std; | ||
|
||
const int n = 8; | ||
|
||
int col, t[n], sol; | ||
|
||
bitset<n> orw; | ||
bitset<n * 2 - 1> odd, odu; | ||
|
||
void backtrack(int c) { | ||
if (c == n) { | ||
cout << setw(2) << ++sol << " "; | ||
for (int i = 0; i < n; i++) { | ||
cout << setw(2) << t[i] + 1; | ||
} | ||
cout << endl; | ||
return; | ||
} | ||
if (col == c) { | ||
backtrack(c + 1); | ||
} else { | ||
for (int r = 0; r < n; r++) { | ||
if (!orw[r] && !odd[r - c + n - 1] && !odu[r + c]) { | ||
orw[r] = odd[r - c + n - 1] = odu[r + c] = true; | ||
t[c] = r; | ||
backtrack(c + 1); | ||
orw[r] = odd[r - c + n - 1] = odu[r + c] = false; | ||
} | ||
} | ||
} | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false); | ||
cout.fill(' '); | ||
int d; | ||
cin >> d; | ||
for (int q = 0; q < d; q++) { | ||
if (q > 0) { | ||
cout << endl; | ||
} | ||
cout << "SOLN COLUMN" << endl; | ||
cout << " # 1 2 3 4 5 6 7 8" << endl; | ||
cout << endl; | ||
int row; | ||
cin >> row >> col; | ||
t[--col] = --row; | ||
orw.reset(); | ||
odd.reset(); | ||
odu.reset(); | ||
orw[row] = odd[row - col + n - 1] = odu[row + col] = true; | ||
sol = 0; | ||
backtrack(0); | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.