fork download
  1. program ghost;
  2. var
  3. str: string;
  4. k: integer;
  5.  
  6. function isAlpha(ch: char) : boolean;
  7. begin
  8. isAlpha := ((ch >= 'a') and (ch <= 'z')) or ((ch >= 'A') and (ch <= 'Z'));
  9. end;
  10.  
  11. function isDigit(ch: char) : boolean;
  12. begin
  13. isDigit := ((ch >= '0') and (ch <= '9'));
  14. end;
  15.  
  16. function startWith(s: string; k: integer) : boolean;
  17. var
  18. i: integer;
  19. result: boolean;
  20. begin
  21. result := true;
  22. if (length(s) < (k + 1)) then
  23. begin
  24. result := false;
  25. end
  26. else
  27. begin
  28. for i := 1 to k do
  29. begin
  30. if (not isAlpha(s[i])) then
  31. begin
  32. result := false;
  33. break;
  34. end;
  35. end;
  36. if ((result <> true) and (ord(s[k + 1]) - ord('0') <> k)) then
  37. begin
  38. result := false;
  39. end;
  40. end;
  41. startWith := result;
  42. end;
  43. begin
  44. str := 'asd3';
  45. k := 3;
  46. writeln(startWith(str, k)); // true
  47. writeln(startWith('asd', 3)); // false
  48. writeln(startWith('asdf4', 4)); // true
  49. end.
Success #stdin #stdout 0.01s 4112KB
stdin
Standard input is empty
stdout
True
False
True