Created
August 15, 2017 03:37
-
-
Save ivanjr0/2bc9821efd9f6b18307c01ace193cadf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <cmath> | |
#include <cassert> | |
#include <iostream> | |
#include <string> | |
#include <sstream> | |
using namespace std; | |
bool is_subseq(const string &h, const string &n) { | |
int j = 0; | |
for (int i = 0; i < h.size() && j < n.size(); i++) { | |
if (n[j] == h[i]) j++; | |
} | |
return j == n.size(); | |
} | |
string string_pow(const string &s, int n) { | |
stringstream ss; | |
for (int i = 0; i < s.size(); i++) { | |
for (int j = 0; j < n; j++) { | |
ss << s[i]; | |
} | |
} | |
return ss.str(); | |
} | |
int gustavo(const string &h, const string &n) { | |
int max = ceil(h.size() / n.size()); | |
int left = 1; | |
int right = max; | |
int result = 0; | |
while (left <= right) { | |
int mid = (left + right) / 2; | |
if (is_subseq(h, string_pow(n, mid))) { | |
result = mid; | |
left = mid + 1; | |
} else { | |
right = mid - 1; | |
} | |
} | |
return result; | |
} | |
int main() { | |
int T; | |
cin >> T; | |
string h, n; | |
while (T--) { | |
cin >> h >> n; | |
cout << gustavo(h, n) << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment