EaglePB2's Competitive Programming Writeups
  • Home Page
  • Why Python?
  • Why 10^9 + 7?
  • General Formatting Title
  • 🇲🇾CodeNection
    • 2021
      • Closed Cateogry
        • Attend Talks
        • Distant Relatives
        • Concert
        • Mamak
        • Fair Contest
      • Open Preliminary Round
        • f(Aibohphobia)^-1
        • Did they cheat?
        • Semester Breaks
      • Open Final Round
        • Ways 1
        • Circular Campus
        • A joke
        • 🥰Last year when life was better
        • Thank You Pizza
    • 2023
      • Test Round
        • Codey and Alphabetical Scoring
        • Codey and Binary Guesser
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Hide-and-Seek
        • Codey and Math
        • Codey and Textbooks
        • Codey and Money
        • Codey and Team Selection
        • Codey and Painted Tree
        • Codey and Number Grid
        • Codey and Crimes
      • Final Round
        • Codey and CodeNection 2
        • Codey and Connection
        • Codey and Schedule
        • Codey and School Supplies
        • Codey and Zombies
        • Codey and Sightseeing
        • Codey and Apples
        • Codey and Facto
        • Codey and Zoey
    • 2024
      • Test Round
        • Codey and Sunday
        • Codey and Takoyaki
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Pebbles
        • Codey and Spam
        • Codey and Coins
        • Codey and Rectangles
        • Codey and Manuscript
        • Codey and Recipes
        • Codey and Toy Kingdom
        • Codey and Peaks
      • Final Round
        • Codey and Exit
        • Codey and Gardening
        • Codey and Symbol
        • Codey and Rectangles 2
        • Codey and Jutsu
        • Codey and Toy Kingdom 2
        • Codey and Speeches
  • ABaKoDa
    • 2023
      • Round 1
        • Problem Letters
        • Problem Statistics
        • Rankings Order
        • Rankings Search
      • Round 2
        • Abakoda Letters
        • Borrowed Words
        • Kensorship
        • Duel Languages
  • Meta Coding Competitions
    • 2011
      • Qualification Round
        • Double Squares
        • Peg Game
        • Studious Student
      • Round 1A
        • Diversity Number
        • Turn on the Lights
        • Wine Tasting
      • Round 1B
        • Chess 2
        • Diminishing Circle
        • Slot Machine Hacker
      • Round 1C
        • N-Factorful
        • Polynomial Factoring
        • Risky Slide
      • Round 2
        • Bonus Assignments
        • Scott's New Trick
        • Studious Student II
      • Final Round
        • Alien Game
        • Party Time
        • Safest Place
  • EaglePB2's Special
    • Hong Kong Identity card
    • Cycle Prefix Averages
    • Word Squares
Powered by GitBook
On this page
  • Question
  • Input Format
  • Constraints
  • Output Format
  • Sample Inputs:
  1. ABaKoDa
  2. 2023
  3. Round 2

Kensorship

https://codeforces.com/group/cRJbcAFEwS/contest/487230/problem/C

Question

Kody desided that the nekst step in eliminating hiram na titik is implementing a tekst pilter to kensor out all their okkurenses in the Abakoda Diskord tsannel. He wants this tekst pilter to habe the pollowing punktionality, and asks you to kode it por him.

A word is a contiguous sequence of upper and/or lowercase English letters (A to Z and a to z). Any other characters are either spaces or punctuation, which are used to separate (or delimit) the different words in a text. To censor a word means to replace it with a number of asterisks * equal to that word's original length (e.g. duck becomes ****). Note that spaces and punctuation should never be included in censorship, as they are not part of a word.

Rather than only censoring hiram na titik, let's make our program a little bit more general. First, you will be given a string describing the set of forbidden letters. Then, you will be given a single line of text, which contains one or more words separated by spaces/punctuation. Censor every word in that line of text that contains a forbidden letter, leaving spaces, punctuation, and non-forbidden words exactly the same.

Input Format

First, a line containing some number of distinct uppercase English letters, describing the set of forbidden letters in this test case. Note that the lowercase forms of these letters are forbidden, too.

This is followed by another line, the text that needs to be censored.

Constraints

  • At least one letter will be forbidden.

  • The text will not begin or end with spaces.

  • There will never be two consecutive spaces in the text.

  • The text will contain at least one word.

  • The text will only contain upper and/or lowercase English letters, spaces, and punctuation characters from among .,?!'-";()

  • The text will not exceed 10510^5105 characters in length (this includes spaces and punctuation).

Output Format

Output the exact same line of text from the input, but having censored all words that contain a forbidden letter.

Sample Inputs:

Input

CFJQVXZ
Pack my box with five dozen liquor jugs.

Output

**** my *** with **** ***** ****** ****.

Input

CFJQVXZ
"Ang hindi magmahal sa sariling wika, daig pa ang hayop at malansang isda."

Output

"Ang hindi magmahal sa sariling wika, daig pa ang hayop at malansang isda."

Input

NOI
What counts as a word? Our definition's far from perfect.

Output

What ****** as a ****? *** **********'s far **** perfect.

Explanation

definition's is treated as two separate words (definition & s). However, for this problem, the definition should be strictly followed in order to get an Accepted.


Solution — Special Character = space

Extension of Problem B.

Basically, we just need to break a sentence into several strings, for each string, break each string to chars. if one of the chars contains the censorship characters, we will turn all string into asterisks. That's all I guess?

Here's the solution for now:

import string

def censor_words(input_check, key):
    for i in key:
        if i in input_check:
            return True
    return False

characters = input().lower()
sentence = input()
result = []
for word in sentence.split():
    censored_word = "*" * len(word) if censor_words(word.lower(), characters) else word
    if word[-1] in string.punctuation:
        result.append(censored_word[:-1] + word[-1])
    else:
        result.append(censored_word)
print(" ".join(result))

PreviousBorrowed WordsNextDuel Languages

Last updated 2 months ago

Page cover image