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

×

FRIEZA - Editorial

PROBLEM LINKS:

Practice
Contest

Authors:

Anmol Rishi
Akshat Girdhar
Chirag Gupta

DIFFICULTY:

CakeWalk

PREREQUISITES:

Arrays, Strings

PROBLEM:

Iterate over the string and output the required digits.

EXPLANATION:

This is a simple problem in which we just have to iterate over the string and store the required digits in an array. You are given a string "frieza"(let it be called f) and each input will consist of a string(let's assume it to be S). So now what you have to do is count continuous presence or non-presence of character from string f in S.

Step 1 - We first create a character array of length 6 and store the letters [f,r,i,e,z,a] in it. We also create an output array with size equal to the length of S. This is because the maximum size of the array will be equal to the length of string S (when S = "fdfdfdfdfdfdf........and so on", output array will have elements = {1,1,1,1,1,1,1,..... and so on}).

Step 2 - Loop to iterate over S. For each iteration, we check if the current letter belongs to the array [f,r,i,e,z,a] and increment a count variable accordingly. We also check if the previous letter also belonged to this array. If yes, then we increment the count, else we just save the count in the output array and increment its index.

Step 3 - We print the output array. We keep printing till the end of the array or until we get a zero.This is because when S="freid" the array created will be {4,1,0,0,0}. And thus we have to stop printing as soon as we get a zero.

SOLUTION:

Java

This question is marked "community wiki".

asked 23 Jun '18, 20:58

anmolrishi's gravatar image

3★anmolrishi
1
accept rate: 0%

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,684
×1,652
×847
×349
×5
×2

question asked: 23 Jun '18, 20:58

question was seen: 76 times

last updated: 23 Jun '18, 20:58