fork download
  1. using System;
  2. using System.Linq.Expressions;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. String[] strings = {"4,78,6", "2,6,24", "31", "30"};
  12. foreach (string s in strings)
  13. {
  14. Console.WriteLine("'{0}': {1}", s, isMatch(s));
  15. }
  16. }
  17. static Boolean isMatch(string s) {
  18. string pattern = @"^(?:[1-9]|[12]\d|30)(?:,(?:[1-9]|[12]\d|30))*$";
  19. List<String> a = s.Split(',').ToList();
  20. return Regex.Match(s, pattern).Success && a.Count == a.Distinct().Count();
  21. }
  22. }
Success #stdin #stdout 0.04s 134592KB
stdin
Standard input is empty
stdout
'4,78,6': False
'2,6,24': True
'31': False
'30': True