THINK FIRST·CODE LATER

← All labs

Redact personal data before it reaches the AI provider

Problem

Before a student's question is sent to the external AI provider, StudyBuddy must remove identifiers.

Read questions, one per line, until the end of input. Replace, in this order:

  1. Chinese resident ID numbers — 17 digits followed by a digit or X (18 characters, not part of a longer digit run) → [ID_CARD]
  2. email addresses — name@domain.tld where name and domain use letters, digits, ., _, - → [EMAIL]
  3. Chinese mobile numbers — 1 followed by a digit 3–9 and 9 more digits (11 digits, not part of a longer digit run) → [PHONE]
  4. WKU student IDs — exactly 7 digits (not part of a longer digit run) → [STUDENT_ID]

Output for each line: Q<k>: <redacted text>; if anything was replaced, add (redacted: n) with the number of replacements. A line containing an [ID_CARD] is sensitive: print Q<k>: BLOCKED - remove your ID card number and ask again instead (nothing is sent). At the end: Sent: s, Blocked: b, Redactions: r (r counts redactions in sent lines only).

Input:

Why does my loop never end?
My ID is 1234567 and my email is yuki@wku.edu.cn, why can't I log in?
Call me at 13812345678 about lab 3
My ID card is 33030219990101123X please check my account

Output:

Q1: Why does my loop never end?
Q2: My ID is [STUDENT_ID] and my email is [EMAIL], why can't I log in? (redacted: 2)
Q3: Call me at [PHONE] about lab 3 (redacted: 1)
Q4: BLOCKED - remove your ID card number and ask again
Sent: 3, Blocked: 1, Redactions: 3

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

s11-1-data-1.txt

Why does my loop never end?
My ID is 1234567 and my email is yuki@wku.edu.cn, why can't I log in?
Call me at 13812345678 about lab 3
My ID card is 33030219990101123X please check my account
What your program must print for s11-1-data-1.txt
Q1: Why does my loop never end?
Q2: My ID is [STUDENT_ID] and my email is [EMAIL], why can't I log in? (redacted: 2)
Q3: Call me at [PHONE] about lab 3 (redacted: 1)
Q4: BLOCKED - remove your ID card number and ask again
Sent: 3, Blocked: 1, Redactions: 3

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < s11-1-data-1.txt

Windows PowerShell does not understand <:

Get-Content s11-1-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.