Author |
Message |
eNc
|
Posted: 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 ! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Tue Jun 15, 2004 11:55 pm Post subject: (No 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.
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
eNc
|
Posted: Wed Jun 16, 2004 6:37 am Post subject: (No subject) |
|
|
... that only finds it once... |
|
|
|
|
|
SuperGenius
|
Posted: Wed Jun 16, 2004 9:51 am Post subject: (No subject) |
|
|
then figure out a way to make if find it more than once. |
|
|
|
|
|
beard0
|
Posted: Wed Jun 16, 2004 10:02 am Post subject: (No 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 |
|
|
|
|
|
eNc
|
Posted: Wed Jun 16, 2004 10:08 am Post subject: (No 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
|
|
|
|
|
|
|
beard0
|
Posted: Wed Jun 16, 2004 10:22 am Post subject: (No 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! |
|
|
|
|
|
Tony
|
Posted: Wed Jun 16, 2004 3:49 pm Post subject: (No subject) |
|
|
a hint : once you found a match, remove it so it doesnt get counted again. Continue on searching untill 0 matches found. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Sponsor Sponsor
|
|
|
eNc
|
Posted: Thu Jun 17, 2004 11:06 am Post subject: (No 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 ? |
|
|
|
|
|
s_climax
|
Posted: Thu Jun 17, 2004 12:47 pm Post subject: (No 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
|
|
|
|
|
|
|
eNc
|
|
|
|
|
eNc
|
Posted: Fri Jun 18, 2004 3:31 am Post subject: (No subject) |
|
|
me need posts = Spam, -2 bits |
|
|
|
|
|
templest
|
|
|
|
|
Dan
|
Posted: Fri Jun 18, 2004 9:59 pm Post subject: (No subject) |
|
|
Posting in spam dose not make your count go down, it just dose not count posts in the spam section. |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
eNc
|
Posted: Sat Jun 19, 2004 2:24 pm Post subject: (No 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] |
|
|
|
|
|
|