2024_4
#include <iostream> #include <cstring> #include <iomanip> using namespace std; int countItUp(char *s, char *str) { int len = strlen(str); int count = 0; char *p = s; while ((p = strstr(p, str)) != nullptr) { // Ensure there's enough space for another full substring if (strlen(p) >= len && strncmp(p + len, str, len) == 0) { count++; // Found a consecutive appearance p += len; // Skip past the first occurrence } else { p += 1; // Move forward by 1 if not consecutive } } return count; } int main() { char str[20]; cin>>str; int n; cin >> n; char s[151]; int results[150/4+1] = {0}; cin.ignore(); int max = 0; for (int i = 0; i < n; i++) { cin.getline(s, 151); int count = countItUp(s,str); //cout << count << endl; if (count > max) max = count; results[count]++; } for (int i = 0; i <= max; i++) { cout << i << ": " << results[i] << endl; } return 0; }
Leave a Comment