VWORDPOW - Sức mạnh của ngôn từ

Tác giả: happyboy99x

Ngôn ngữ: C++

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
using namespace std;

char s[1002][1002], g[102][32];
int n, m, ls[1002], lg[102];

void enter() {
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; ++i) {
		scanf("%s%n", s[i], ls+i);
		for(int j = 0; j < ls[i]; ++j) if(s[i][j] >= 0x41 && s[i][j] <= 0x5a) s[i][j] += 0x20;
	}
	for(int i = 0; i < m; ++i) {
		scanf("%s%n", g[i], lg+i);
		for(int j = 0; j < lg[i]; ++j) if(g[i][j] >= 0x41 && g[i][j] <= 0x5a) g[i][j] += 0x20;
	}
}

void solve() {
	for(int i = 0; i < n; ++i) {
		int res = 0;
		for(int j = 0; j < m; ++j)
			for(int x = 0, y = 0; x < ls[i]; ++x)
				if(s[i][x] == g[j][y]) if(++y == lg[j]) { ++res; break; }
		printf("%d\n", res);
	}
}

int main() {
	enter();
	solve();
	return 0;
}

Download