2024_1
#include <iostream> #include <cctype> #include <cstring> #include <iomanip> using namespace std; int countItUp(char* s, char* s_) { int counter = 0; const char *p = strstr(s, s_); while (p != nullptr) { // Added bound check counter++; p = strstr(p + 1, s_); } return counter; } int main() { char s_[21]; cin.getline(s_, 21); int n; cin >> n; cin.ignore(); // Consume the newline after n int k = 100/strlen(s_) + 1; int results[k] = {0}; // Changed size to n as per original code char s[101]; int a = 0; for (int i = 0; i < n; i++) { cin.getline(s, 101); int counter = countItUp(s, s_); if(counter<=k) { results[counter]++; } if (counter > a) a = counter; } // Keep original output format exactly as in the initial code for (int i = 0; i <= a; i++) { cout << i << ": " << results[i] << endl; } return 0; }
Leave a Comment