
-----------------------------------
eNc
Tue Jun 15, 2004 11:06 pm

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 !

-----------------------------------
Tony
Tue Jun 15, 2004 11:55 pm


-----------------------------------

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. 


-----------------------------------
eNc
Wed Jun 16, 2004 6:37 am


-----------------------------------
... that only finds it once...

-----------------------------------
SuperGenius
Wed Jun 16, 2004 9:51 am


-----------------------------------
then figure out a way to make if find it more than once.

-----------------------------------
beard0
Wed Jun 16, 2004 10:02 am


-----------------------------------
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

-----------------------------------
eNc
Wed Jun 16, 2004 10:08 am


-----------------------------------
werd... umm ok so this is what im thinking


for i : 1..length(sentence)
c := index(sentence, find)
if c not= 0 then
count := count + 1
end if
end for


-----------------------------------
beard0
Wed Jun 16, 2004 10:22 am


-----------------------------------
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!

-----------------------------------
Tony
Wed Jun 16, 2004 3:49 pm


-----------------------------------
a hint : once you found a match, remove it so it doesnt get counted again. Continue on searching untill 0 matches found.

-----------------------------------
eNc
Thu Jun 17, 2004 11:06 am


-----------------------------------
ok lets c here


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 ?

-----------------------------------
s_climax
Thu Jun 17, 2004 12:47 pm


-----------------------------------
It should be this.

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


-----------------------------------
eNc
Thu Jun 17, 2004 1:35 pm


-----------------------------------
thats what i meant, as you can see there are a lot of errors, it was too early to think :P

Actually in order to work even better to accept a full sentence it should be this


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 


:D

-----------------------------------
eNc
Fri Jun 18, 2004 3:31 am


-----------------------------------
me need posts = Spam, -2 bits

-----------------------------------
templest
Fri Jun 18, 2004 9:46 pm


-----------------------------------
me need posts = Spam, -2 bits

wtf? did you just get rid of two of your own bits? :?

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? :shock:

Because I've know for a fact I've posted more than 89 times.  :roll:

-----------------------------------
Dan
Fri Jun 18, 2004 9:59 pm


-----------------------------------
Posting in spam dose not make your count go down, it just dose not count posts in the spam section.

-----------------------------------
eNc
Sat Jun 19, 2004 2:24 pm


-----------------------------------
woah im not getting this -2 bits sytem and whatever it is, im confused


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


-----------------------------------
this_guy
Mon Jun 21, 2004 9:21 am


-----------------------------------
nothing to do with this, but i was trying the program, and i just learned that you cant copy and paste in turing!!

-----------------------------------
Andy
Fri Jul 02, 2004 10:57 am


-----------------------------------
^= spam -2 bits
