You are not logged in. Please login at www.codechef.com to post your questions!

×

CDSTTS - Editorial

PROBLEM LINK:

Practice

Contest

Author: samhenry97 Editorialist: samhenry97

DIFFICULTY:

Cakewalk

PREREQUISITES:

Regex, State Machine

PROBLEM:

Count the number of certain types of tokens in given text.

QUICK EXPLANATION:

Run through using a state machine to count the tokens.

EXPLANATION:

We can use a state machine or regular expressions to find identifiers. The regular expression for an identifier is [_a-zA-Z][_a-zA-Z0-9]*. Once an identifier is found, test if it is a keyword. We use a map or dictionary to keep track of the counts of each item. If the item is a keyword, add one to the count. If the item is an identifier, add one to the identifier count.

At the end, we just print everything that we've totaled up.

AUTHOR'S AND TESTER'S SOLUTIONS:

This question is marked "community wiki".

asked 25 May '18, 07:58

samhenry97's gravatar image

2★samhenry97
31
accept rate: 0%

edited 29 May '18, 12:50

admin's gravatar image

0★admin ♦♦
19.7k350498541

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×15,480
×1,600
×17
×12

question asked: 25 May '18, 07:58

question was seen: 88 times

last updated: 29 May '18, 12:50