Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 HELP PLEASE
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
eNc




PostPosted: 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
Sponsor
sponsor
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
eNc




PostPosted: Wed Jun 16, 2004 6:37 am   Post subject: (No subject)

... that only finds it once...
SuperGenius




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
eNc




PostPosted: 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




PostPosted: 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




PostPosted: Thu Jun 17, 2004 1:35 pm   Post subject: (No 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
eNc




PostPosted: Fri Jun 18, 2004 3:31 am   Post subject: (No subject)

me need posts = Spam, -2 bits
templest




PostPosted: Fri Jun 18, 2004 9:46 pm   Post subject: (No 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
Dan




PostPosted: 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




PostPosted: 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]
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 17 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: