fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. class Entry
  6. {
  7. static string MySpecialFunction(IEnumerable<string> items, int limit)
  8. {
  9. var sb = new StringBuilder();
  10.  
  11. bool delimit = false;
  12. int count = 0;
  13.  
  14. foreach (var item in items) {
  15. if (limit == 0) {
  16. ++count;
  17. } else {
  18. if (delimit) {
  19. sb.Append(", ");
  20. }
  21.  
  22. delimit = true;
  23. sb.Append(item);
  24.  
  25. --limit;
  26. }
  27. }
  28.  
  29. if (count != 0) {
  30. sb.Append(", and ");
  31. sb.Append(count);
  32. sb.Append(" more.");
  33. }
  34.  
  35. return sb.ToString();
  36. }
  37.  
  38. static void Main()
  39. {
  40. Console.WriteLine(MySpecialFunction(new[] {
  41. "sample11", "sample21", "sample31", "sample41", "sample51"
  42. }, 3));
  43. }
  44. }
Success #stdin #stdout 0.03s 33904KB
stdin
Standard input is empty
stdout
sample11, sample21, sample31, and 2 more.