Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Taking a part 1001001101


  • Please log in to reply

#1
Ineedhelp37

Ineedhelp37

    New Member

  • Member
  • Pip
  • 1 posts
Taking a part 1001001101
I need to write a program that can output information for every one and zero but I’m not sure what function to use. This is a win32 console. The data is just being typed in.

Input:1001001101
The output would look like
Yes 1 times
No 2 times
Yes 1 times
No 2 times
Yes 2 times
No 1 times
Yes 1 times

How would I go about doing this?

Edited by Ineedhelp37, 01 March 2006 - 12:13 PM.

  • 0

Advertisements


#2
destin

destin

    Member

  • Member
  • PipPip
  • 53 posts
What language?
  • 0

#3
Krizniak

Krizniak

    Member

  • Member
  • PipPip
  • 33 posts
Here are the steps, (independant from any language), of the algorithm construction.

As I presume you ask help for a school job [am I right ??], I'll give you the steps, and not the complete source.
If you want to learn, you'll have to understand, so... I hope this will help...
  • Get input string in a specific storage area, named 'strInput'
  • Parse strInput, char by char. For each car that I meet : WorkOnTheChar and display when necessary
  • done !
OK. So now, I parse the string, but I have to count each group of chars...
Here is what immediately come in my mind. Anybody does not think like I do, so you may have any number of valid helps. :

take one by one, adding to a counter when it's the same char used, display char and reinitialize when we change the char.

This need some reflexion. I need something to remember if I previously (in the step just before) work with 0 or 1. When I start with the first char in the string, I have to consider that previously, I was dealing with something not defined.
So... The count. When I start with a char, which is different from the previous char, I must start to count with 1 (the current) and memorize this current char as the "future previous char" that I'll need in the following iteration of the parsing. And when the current char is the same char than the previous char, I have to increment my counter (add 1 to its value - I don't know what is your level in programming... so I have to define whatever I can presume unknown).
But... Wait ! I have to display something, no ? And ideally, I have to display something about a char just before I start to count the next one. Right ?

So, here is a come back :
  • Get input string in a specific storage area, named 'strInput'
  • move spaces or any char different from 0 or 1 in a storage area, named 'previousChar'
    This will assure that I will, for the first char of the string, have the count=1 instruction running...
  • Parse strInput, char by char. For each car that I meet, that I'll name currentChar :

  • if currentChar is different from previousChar
    • if count > 0, display "Char :" previousChar " : " count " times"
    • put 1 in count
    • put currentChar in previousChar
  • else
    • Add 1 to count
  • end of the test

  • and this is done ! you can display your "That's all, folks !"
Of course, this is a low level approach : I made some presumptions :
  • admit that I can parse a string, char by char. This need some loop way or iterator approach in your language. As many of them can deal with this, I could presume that you can find the way in your own language
  • admit that I can easily extract a char from a string, and that I can compare two chars together. Once again, this is often a basis on most languages...
  • admit that I have a way to display strings and numbers independently from their internal representation. This is again a basis on most language.
I didn't consider other high level abilities : extracting sub strings, regular expressions and so on... SO, it's up to you to translate those instructions into your language...


What you have to do is : I have to do this myself, I just can do this, and this, but not this, nor this... How do I do ???

If you do not understand any step, you're welcome... :tazz:

Oh yes, I did forgot something : There is a volunteer "missing instruction". Take care of what you write. And take care of every value you use !!
Come back to say me where I did miss the instruction.
[Yeah, typically teacher's mind... As I was one, it's perfect :)]
  • 0

#4
sweft

sweft

    Member

  • Member
  • PipPipPip
  • 123 posts
Wow-- that is a great tutoural! Thanks for sharing.!.!
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP