Questions? Email sfo.lax6776@gmail.com

Join our weChat group or follow us on Facebook

©2019 by Legion of Learners

sfolax6776
Nov 6

Senior2019-Set 3 - Recursive Functions and CNS 3

9 comments

Edited: 2 days ago

awesomeface259
5 days ago

2. A

3. A

12. D

kchen4000
5 days ago

2)a 3)A 12)D

kchen4000
5 days ago

hello world

sfolax6776
5 days ago

Solute to the Ks

Steven
4 days ago

 

 

 

Steven
4 days ago

 

 

colinzhao777
4 days ago

 

20191110_203840jpg

 

colinzhao777
4 days ago

#include <bits/stdc++.h>

using namespace std;

#define vi vector<int>

#define ii pair<int,int>

#define vs vector<string>

typedef uint64_t ll;

 

bool check(string a, string b, string search) {

if (search == "DR") return a == b;

else if (search == "MR") {

if (a.size() == 1) return false;

reverse(b.begin(), b.end());

return a == b;

} else if (search == "IR") {

if (a.size() == 1) return false;

reverse(b.begin(), b.end());

for (int i = 0; i < (int)b.size(); i++) {

if (b[i] == 'A') b[i] = 'L';

else if (b[i] == 'L') b[i] = 'A';

else if (b[i] == 'C') b[i] = 'S';

else b[i] = 'C';

}

return a == b;

} else if (search == "ER") {

if (a.size() <= 2 || a.size() % 2 == 0) return false;

string c = "";

int on1 = (a.size() - 1) / 2;

for (int i = 0; i < (int)a.size(); i++) {

on1 += i * pow(-1, i + 1);

c.append(b.substr(on1, 1));

}

return a == c;

} else {

if (a.size() <= 2 || a.size() % 2 == 0) return false;

string c = "";

int on1 = (a.size() - 1) / 2;

for (int i = 0; i < (int)a.size(); i++) {

on1 += i * pow(-1, i);

c.append(b.substr(on1, 1));

}

return a == c;

}

}

 

int main() {

string dna, search;

cin >> dna >> search;

set<string> ans;

for (int i = 0; i < (int)dna.size(); i++) {

for (int j = 1; j < (int)dna.size() - i && i + 2 * j < (int)dna.size(); j++) {

string a = dna.substr(i, j), b = dna.substr(i + j, j), c = dna.substr(i, 2 * j);

if (check(a, b, search)) ans.insert(c);

}

}

for (auto it : ans) cout << it << ", ";

if (ans.size() == 0) cout << "NONE";

cout << endl;

}

 

sfolax6776
4 days ago

Great, will you double check test data #6 and #8? - something minor

New Posts