diff --git a/contests/Cadernaveis/URI1364.cpp b/contests/Cadernaveis/URI1364.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3cc36f91504c73186dda92c102bc7eb5263c95fd --- /dev/null +++ b/contests/Cadernaveis/URI1364.cpp @@ -0,0 +1,59 @@ +#include <bits/stdc++.h> + +#define EPS 1e-6 +#define MOD 1000000007 +#define inf 0x3f3f3f3f +#define llinf 0x3f3f3f3f3f3f3f3f + +#define fi first +#define se second +#define sz size() +#define pb push_back +#define ende '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define mset(x, y) memset(&x, (y), sizeof(x)) + +using namespace std; + +typedef long long ll; +typedef pair<int,int> ii; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int n, m; + while (cin >> n >> m && (n || m)) { + vector<string> emo(n); + for (auto &i : emo) cin >> i; + cin.ignore(); + + int ans = 0; + for (int i = 0; i < m; ++i) { + string s; + getline(cin, s); + + for (int j = 0; j < s.sz; ++j) { + for (int k = 0; k < n; ++k) { + if (s[j] == emo[k].back()) { + for (int l = j, ll = emo[k].sz - 1; ll >= 0 && l >= 0; ll--, l--) { + if (s[l] != emo[k][ll]) + break; + + if (ll == 0) { + s[j] = ' '; + ans++; + } + } + } + } + } + } + + cout << ans << ende; + } + + return 0; +}