using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
class Program
{
// Fast O(1) lookup
private static readonly HashSet<string> Forbidden = new(StringComparer.OrdinalIgnoreCase) {
"badword",
"evil",
"kill",
"nasty",
"terrible"
};
public static bool ContainsForbidden(string input) {
// Normalize: lowercase + split on non-alphanumeric
var words = Regex.Split(input.ToLower(), "[^a-z0-9]+");
foreach (var w in words) {
if (Forbidden.Contains(w))
return true;
}
return false;
}
static void Main()
{
string s = "This text contains a badword inside";
if (ContainsForbidden(s))
Console.WriteLine("Forbidden word detected");
else
Console.WriteLine("No forbidden words found");
}
}
/*
run:
Forbidden word detected
*/