Area 01 · Data manipulation
Name list cleaner
A registration desk typed names by hand. Clean them into proper case, reject the ones that cannot be names, then let the clerk search the cleaned list.
- Spec no.
- HO-01
- Level
- Warm-up
- Time box
- 45 min
- Reference
- Java · C#
- Grading
- Self-assessed · rubric is ours, not DICT's
01 Coverage
| Area | Sub-skills practised | Role |
|---|---|---|
| 01 Data manipulation | String, Validation, ArrayList handling, Searching | Primary |
| 06 Control structures | Conditional, Iteration | Also |
Sign up to start coding practice
Read the task freely. An account is required before editing and running a solution. Code runs also need an internet connection.
Sign up or sign in02 Requirements
- Read a count n (1 to 20). If it is not a whole number in range, print Invalid count and stop.
- Read n lines. Trim each one and collapse runs of spaces into one space.
- A valid name is 2 to 40 characters and contains only letters, spaces, hyphens, apostrophes and periods. For an invalid line print Line k: invalid, where k counts from 1.
- Tidy valid names: all lower case, then upper-case the first letter and any letter after a space or hyphen. Keep them in a growable list (ArrayList / List<T>).
- Print the cleaned names in input order.
- Read one search term. Print Matches for "term": and then every cleaned name that contains the term, ignoring case, or No match.
03 Input and output
- Line 1: n
- Next n lines: one raw name each
- Last line: a search term
- One Line k: invalid message per rejected line, as it is read
- Cleaned names, one per line
- The match header, then matches or No match
4
juan dela cruz
MARIA-CLARA santos
r2d2
ana o'neil
cruzLine 3: invalid
Juan Dela Cruz
Maria-Clara Santos
Ana O'neil
Matches for "cruz":
Juan Dela CruzMatch the sample exactly first, then write at least two test inputs of your own.
04 Edge cases to test
- A count of 0, 21 or abc
- A name with digits, such as r2d2
- Apostrophes: ana o'neil becomes Ana O'neil (the rule only capitalises after a space or hyphen)
- A search term in a different case from the stored name
05 Starter outline and hints
read n; if not 1..20 → print Invalid count, stopnames = new listfor k in 1..n: t = collapseSpaces(trim(readLine)); if !isValid(t) print Line k: invalid else names.add(tidy(t))print each nameterm = lower(readLine); print header; print names whose lower form contains term, or No match
Hint 1
Collapse spaces with a regular expression (\s+ → one space) or a loop that skips a space after a space.
Hint 2
For tidy, keep a boolean 'capitalise next' that becomes true after a space or hyphen.
06 Practice rubric
| Criterion | Sub-skills | Look for | Pts |
|---|---|---|---|
| String processing | String | Trim, space collapse and proper-case rule match the sample exactly. | 35 |
| Validation | Validation | Count and name rules enforced with clear messages; no crash on bad input. | 25 |
| List handling | ArrayList handling | Valid names kept in a growable list; invalid ones never added. | 15 |
| Search | Searching | Case-insensitive contains search over the list, with a no-match message. | 15 |
| Readability | Conditional | Separate isValid and tidy functions; no repeated blocks. | 10 |
| Total | 100 | ||
Our own weighting for practice. It is not the DICT scoring scheme.
07 Self-check
Tick only what you have verified by running your own program.
Loading saved checks…
08 Reference solution
Both versions compiled and reproduced the sample output on Java 21 and .NET 8 when this site was built. Reference solutions are in Java and C#. The 2023 FAQ copy also lists C, C++ and Visual Basic 6.0 / .NET; the same structure carries over, but you will need your language's own file and database APIs.
Try the whole brief first. The reference is one correct approach, not the only one, and reading it early removes most of the practice value.
09 Exam-day habits
- Work without internet search to simulate exam conditions.
- Type the sample input yourself and compare your output line by line before you look at the reference.