#include #include #include using namespace std; //#define DEBUG_OUTPUT const size_t MAXN = 500001; const size_t MAXM = 5001; const size_t MAXQ = 20; int Q; char clownWords[MAXN]; char druggedWords[MAXQ][MAXM]; int result[MAXQ]; void readInput() { FILE* finp = fopen("clown.in", "r"); fscanf(finp, "%s", clownWords); fscanf(finp, "%d", &Q); for (int i = 0; i < Q; ++i) fscanf(finp, "%s", druggedWords[i]); fclose(finp); #ifdef DEBUG_OUTPUT cout << clownWords << endl; cout << Q << endl; for (int i = 0; i < Q; ++i) cout << druggedWords[i] << endl; #endif } void writeOutput() { FILE* fout = fopen("clown.out", "w"); for (int i = 0; i < Q; ++i) fprintf(fout, "%d\n", result[i]); fclose(fout); #ifdef DEBUG_OUTPUT for (int i = 0; i < Q; ++i) cout << result[i] << endl; #endif } unsigned countOccurrences(char* words) { unsigned count = 0; char* position = clownWords; while (position != '\0') { position = strstr(position, words); if (!position) break; ++position; ++count; } return count; } void solve() { for (int i = 0; i < Q; ++i) result[i] = countOccurrences(druggedWords[i]); } int main() { readInput(); solve(); writeOutput(); return 0; }