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

×

Help me out

How to know whether a character is present in two different words or not? Like "o" is present in both words "boy" and "toy".How will I print it.

asked 05 Feb, 21:16

mdmdmd's gravatar image

2★mdmdmd
11
accept rate: 0%


You can run a check over the entire length of both the strings and check for the character?

link

answered 20 Feb, 18:41

mithil467's gravatar image

2★mithil467
1
accept rate: 0%

You can make a frequency array and traverse both the strings.

If you encounter - 'o' , in the first string,then do a[int('o')-96]++; don't increment it again.

Now, traverse the second string and do the same thing :-)

Finally, if a[int('o')-96]==2; then yes, 'o' is in both the strings !

link

answered 20 Feb, 21:26

secrex's gravatar image

3★secrex
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:

×22

question asked: 05 Feb, 21:16

question was seen: 110 times

last updated: 20 Feb, 21:26