Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- bool buscar(const vector <vector <char> > &mat, const string &s)
- {
- for(int i=0; i<mat.size(); i++)
- {
- for(int j=0; j<mat[i].size(); j++)
- {
- int cont = 0;
- for(int k=0; k<s.size() && j+k < mat[i].size(); k++)
- if(s[k] == mat[i][j+k])
- cont++;
- if(cont == s.size())
- return true;
- }
- }
- return false;
- }
- int main()
- {
- int n, m, k;
- cin >> n >> m >> k;
- vector <vector <char> > mat(n, vector <char> (m)), inv(m, vector <char> (n));
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<m; j++)
- {
- cin >> mat[i][j];
- inv[j][i] = mat[i][j];
- }
- }
- for(int i=0; i<k; i++)
- {
- string s;
- cin >> s;
- string t(s.rbegin(), s.rend());
- if(buscar(mat, s)|| buscar(inv, s) || buscar(mat, t)|| buscar(inv, t))
- cout << "SI" << endl;
- else
- cout << "NO" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment