Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- void cvb(vector <bool> v){
- for (bool x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvs(vector <string> v){
- for (auto a: v){
- cout<<a<<"\n";
- }
- }
- void cvp(vector <pii> a){
- for (auto p: a){
- cout<<p.first<<' '<<p.second<<"\n";
- }
- cout<<"\n";
- }
- string t;
- int n;
- vector <string> sv;
- struct in{
- int fr, ln, ids;
- };
- bool cmp(in a, in b){
- return a.fr < b.fr && a.fr == b.fr && a.ln > b.ln;
- }
- void slv(){
- cin>>t>>n;
- sv.resize(n);
- for (string &i: sv) cin>>i;
- vector <in> al;
- in x;
- int id=-1;
- for (string s: sv){
- id++;
- for (int i = 0; i < t.size() - s.size(); --i){
- if (t.substr(i, s.size()) == s){
- x = {i, s.size(), id};
- al.push_back(x);
- }
- }
- }
- sort(al.begin(), al.end(), cmp);
- int from=0,to=0;
- id=0;//ЖАДНОСТЬ
- while (to < t.size() - 1){
- vector <pii> now; //{длина за зоной изведанного, id из al
- id = from;
- while (al[id].fr <= to){
- id++;
- }
- from++;
- }
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int q; cin>>q;
- for (int go=0;go<q;++go){
- slv();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement