Computer Science Canada

HELP PLEASE

Author:  eNc [ Tue Jun 15, 2004 11:06 pm ]
Post subject:  HELP PLEASE

i need this done asap please nyone !

Write a program that reads a string. It will then read a second string to search for in the first string. Print the number of times the second string appears in the first string

I'm confuzzeled

Help please! thanks !

Author:  Tony [ Tue Jun 15, 2004 11:55 pm ]
Post subject: 

magical key F10 wrote:

Syntax index (s , patt : string ) : int

Description The index function is used to find the position of patt within string s. For example, index ( "chair", "air" ) is 3.

Author:  eNc [ Wed Jun 16, 2004 6:37 am ]
Post subject: 

... that only finds it once...

Author:  SuperGenius [ Wed Jun 16, 2004 9:51 am ]
Post subject: 

then figure out a way to make if find it more than once.

Author:  beard0 [ Wed Jun 16, 2004 10:02 am ]
Post subject: 

As a hint, use substrings in a loop, but for how to do that, you have to figure it out on your own. F10 helps.
Good luck

Author:  eNc [ Wed Jun 16, 2004 10:08 am ]
Post subject: 

werd... umm ok so this is what im thinking

code:

for i : 1..length(sentence)
c := index(sentence, find)
if c not= 0 then
count := count + 1
end if
end for

Author:  beard0 [ Wed Jun 16, 2004 10:22 am ]
Post subject: 

not quite - don't do a for loop, do a regular loop and use a counter for the begining of the substring, which you then set to the end of the searched for string - otherwise, you'll get it counting 3 "air" in "chair"
ie
chair +1
hair +1
air +1
ir +0
r +0
result ? 3

try again!

Author:  Tony [ Wed Jun 16, 2004 3:49 pm ]
Post subject: 

a hint : once you found a match, remove it so it doesnt get counted again. Continue on searching untill 0 matches found.

Author:  eNc [ Thu Jun 17, 2004 11:06 am ]
Post subject: 

ok lets c here

code:

var s, t : string := ""
var count, i : int := 0
put "Enter sentence..."
get s
put "Enter words to find..."
get t
delay (2000)
cls
loop
    i := index (s.t)
    if i not= then
        count := count + 1
        s := s (i + 1 .. *)
    end if
    exit when i = 0
end loop
put count


w00t ?

Author:  s_climax [ Thu Jun 17, 2004 12:47 pm ]
Post subject: 

It should be this.
code:

var s, t : string := ""
var count, i : int := 0
put "Enter sentence..."
get s
put "Enter words to find..."
get t
delay (2000)
cls
loop
    i := index (s, t)
    if i not= 0 then
        count := count + 1
        s := s (i + 1 .. *)
    end if
    exit when i = 0
end loop
put count

Author:  eNc [ Thu Jun 17, 2004 1:35 pm ]
Post subject: 

thats what i meant, as you can see there are a lot of errors, it was too early to think Razz

Actually in order to work even better to accept a full sentence it should be this

code:

var s, t : string
var count, i : int := 0
put "Enter sentence..."
get s:*
put "Enter words to find..."
get t:*
loop
    i := index (s, t)
    if i not= 0 then
        count := count + 1
        s := s (i + 1 .. *)
    end if
    exit when i = 0
end loop
put count


Very Happy

Author:  eNc [ Fri Jun 18, 2004 3:31 am ]
Post subject: 

me need posts = Spam, -2 bits

Author:  templest [ Fri Jun 18, 2004 9:46 pm ]
Post subject: 

eNc wrote:
me need posts = Spam, -2 bits


wtf? did you just get rid of two of your own bits? Confused

By the way, now that's we're on the topic of post counts, Is it just my imagination playing cruel tricks on me, or does my post count go down everytime I post in the spam section? Shocked

Because I've know for a fact I've posted more than 89 times. Rolling Eyes

Author:  Dan [ Fri Jun 18, 2004 9:59 pm ]
Post subject: 

Posting in spam dose not make your count go down, it just dose not count posts in the spam section.

Author:  eNc [ Sat Jun 19, 2004 2:24 pm ]
Post subject: 

woah im not getting this -2 bits sytem and whatever it is, im confused

[mod:d20d19d669]
it is quite simple, when you post in a area other then spam just to get posts some mods get mad and take bits.

-2 bits
[/mod:d20d19d669]

Author:  this_guy [ Mon Jun 21, 2004 9:21 am ]
Post subject: 

nothing to do with this, but i was trying the program, and i just learned that you cant copy and paste in turing!!

Author:  Andy [ Fri Jul 02, 2004 10:57 am ]
Post subject: 

^= spam -2 bits


: