Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- using namespace std;
- bool f;
- int t, n, cur, sz;
- unsigned long long a, b, tmp, stp;
- string str, r, s, ans;
- char ch;
- void fib() {
- tmp = a + b;
- a = b;
- b = tmp;
- }
- int main() {
- cin >> t;
- while (t-- && cin >> n) {
- cin.ignore();
- getline(cin, str);
- a = 0, b = 1; cur = -1;
- ans = "";
- sz = str.size() - 1;
- f = true;
- s = string(str.begin() + 1, str.end());
- r = str;
- reverse(r.begin(), r.end());
- r = string(r.begin() + 1, r.end());
- while (n) {
- fib();
- stp = b - a;
- if (!stp) stp = 1;
- cur += stp;
- if (cur >= (f ? sz + 1 : sz)) {
- if (f) {
- f = false;
- cur--;
- }
- tmp = cur / sz;
- cur %= sz;
- if (tmp % 2)
- ch = r[cur];
- else
- ch = s[cur];
- }
- if (ch != '-') {
- ans += ch;
- n--;
- }
- else
- a = 0, b = 1;
- }
- cout << ans << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement