using System;
using System.Text.RegularExpressions;
public class Test
{
public static void Main()
{
string[] fail = {"ABCDacbd", "ACDE", "ABCDE\n", "_01234", "ABCDÉ", "ABCD́Ē", "ABCDEF_", "A_B_CDEF", "AB_C", "1234567890123456789012345", "123456_789012345678901234"};
string[] ok = {"ACBDEF", "01234", "ABC_DE1", "123456789012345678901234", "12345_789012345678901234"};
foreach (string s in fail) {
Console.WriteLine(s + " " + Validate(s));
}
Console.WriteLine();
foreach (string s in ok) {
Console.WriteLine(s + " " + Validate(s));
}
}
private static bool Validate(string str) {
if (str.Length < 5 || str.Length > 24) {
return false;
}
return Regex.IsMatch(str, @"^[A-Z0-9]+(?:_[A-Z0-9]+)?\z");
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGV4dC5SZWd1bGFyRXhwcmVzc2lvbnM7CgpwdWJsaWMgY2xhc3MgVGVzdAp7CglwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCgl7CgkJc3RyaW5nW10gZmFpbCA9IHsiQUJDRGFjYmQiLCAiQUNERSIsICJBQkNERVxuIiwgIl8wMTIzNCIsICJBQkNERcyBIiwgIkFCQ0TMgcSSIiwgIkFCQ0RFRl8iLCAiQV9CX0NERUYiLCAiQUJfQyIsICIxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1IiwgIjEyMzQ1Nl83ODkwMTIzNDU2Nzg5MDEyMzQifTsKCQlzdHJpbmdbXSBvayA9IHsiQUNCREVGIiwgIjAxMjM0IiwgIkFCQ19ERTEiLCAiMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0IiwgIjEyMzQ1Xzc4OTAxMjM0NTY3ODkwMTIzNCJ9OwoJCQoJCWZvcmVhY2ggKHN0cmluZyBzIGluIGZhaWwpIHsKCQkJQ29uc29sZS5Xcml0ZUxpbmUocyArICIgIiArIFZhbGlkYXRlKHMpKTsKCQl9CgkJQ29uc29sZS5Xcml0ZUxpbmUoKTsKCQkKCQlmb3JlYWNoIChzdHJp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