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

Username:   Password: 
 RegisterRegister   
 DWITE NOVEMBER 25 2005 PROBLEM 3 SOLUTION
Index -> CompSci.ca, Contests -> DWITE
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
xXInsanityXx




PostPosted: Sat Nov 26, 2005 3:09 pm   Post subject: DWITE NOVEMBER 25 2005 PROBLEM 3 SOLUTION

Hi i was wondering if you guys can give me suggestions,feedback, and simplifications to this code. Please feel free to criticize as much as you want.

Please and Thank You

NOTE: PLEASE DO NOT CLAIM THIS CODE AS YOURS -not that its that great-



DATA32.txt
 Description:
This is the data file you require to run the problem succesfully

Download
 Filename:  DATA32.txt
 Filesize:  471 Bytes
 Downloaded:  301 Time(s)


Problem3-1.t
 Description:

Download
 Filename:  Problem3-1.t
 Filesize:  1.54 KB
 Downloaded:  299 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
MysticVegeta




PostPosted: Sat Nov 26, 2005 11:20 pm   Post subject: (No subject)

May I ask where the code is?
Hikaru79




PostPosted: Sun Nov 27, 2005 12:01 am   Post subject: (No subject)

Attached to his post?
MysticVegeta




PostPosted: Sun Nov 27, 2005 1:00 am   Post subject: (No subject)

I cannot see it Confused
Hikaru79




PostPosted: Sun Nov 27, 2005 1:03 am   Post subject: (No subject)

Hm, wierd =/ I'll upload it to this post. Can you see it on mine?


DATA32.txt
 Description:
Sample input data

Download
 Filename:  DATA32.txt
 Filesize:  471 Bytes
 Downloaded:  299 Time(s)


Problem3-1.t
 Description:
Problem 3 source file

Download
 Filename:  Problem3-1.t
 Filesize:  1.54 KB
 Downloaded:  307 Time(s)

MysticVegeta




PostPosted: Sun Nov 27, 2005 11:35 am   Post subject: (No subject)

yeah, heres mine by the ways.
Turing:
var fi, fo : int

open : fi, "DATA31.txt", get
open : fo, "OUT31.txt", put

var lines : string
var numbers : array 1 .. 5 of int
var syl : string := "24682"
var current, high, lineno, original : int := 0


fcn wordCount (word : string) : int
    var count := 0
    for s : 1 .. length (word)
        if word (s) = " " or word (s) = "-" then
            count += 1
        end if
    end for
    result count + 1
end wordCount

proc errors
    for x : 1 .. 5
        numbers (x) := strint (syl (x)) - numbers (x)
        if numbers (x) not= 0 then
            current := abs (numbers (x))
            if current > high then
                original := numbers (x)
                high := current
                lineno := x
            end if
        end if
    end for
end errors

for s : 1 .. 5
    for x : 1 .. 5
        get : fi, lines : *
        numbers (x) := wordCount (lines)
    end for
    errors
    if abs (original) = original then
        put : fo, "LINE ", lineno, " - ", original, " SYLLABLE(S) TOO FEW"
    else
        put : fo, "LINE ", lineno, " - ", abs (original), " SYLLABLE(S) TOO MANY"
    end if
    lineno := 0
    original := 0
    current := 0
    high := 0
end for
close (fi)
close (fo)


I dont know if this is the original one or the bad one.. I sorta screwed up my folder because I was p!ssed earlier. lol Laughing
Cervantes




PostPosted: Sun Nov 27, 2005 11:53 am   Post subject: (No subject)

MysticVegeta: Weren't you supposed to put nothing if all the lines are correct? And won't that put "LINE 0 - 0 SYLLABLE(S) TOO FEW"?
Hikaru79




PostPosted: Sun Nov 27, 2005 12:34 pm   Post subject: (No subject)

This sort of problem is where Java's beautiful library comes in handy. One line,
Java:
StringTokenizer st = new StringTokenizer (in.readLine()," -");
and the whole question just falls apart Very Happy When you're on a timed contest, this sort of thing is great.
Sponsor
Sponsor
Sponsor
sponsor
MysticVegeta




PostPosted: Sun Nov 27, 2005 2:01 pm   Post subject: (No subject)

Cervantes wrote:
MysticVegeta: Weren't you supposed to put nothing if all the lines are correct? And won't that put "LINE 0 - 0 SYLLABLE(S) TOO FEW"?


Never said that one the question that all lines will be correct.

Hikaru: What does the String.Tokenizer do?
Hikaru79




PostPosted: Sun Nov 27, 2005 2:10 pm   Post subject: (No subject)

MysticVegeta wrote:
Cervantes wrote:
MysticVegeta: Weren't you supposed to put nothing if all the lines are correct? And won't that put "LINE 0 - 0 SYLLABLE(S) TOO FEW"?


Never said that one the question that all lines will be correct.

Hikaru: What does the String.Tokenizer do?


StringTokenizer splits up a string based on the presence of certain characters. Notice how when I call the StringTokenizer constructor, I gave it an argument " -"? What that does is take a String, and break it into a different piece whenever it finds a space or a '-' character -- basically solving the problem for you. Then you simply have to count the amount of Tokens that StringTokenizer gives you, and voila, you know how many syllables there are Smile
MysticVegeta




PostPosted: Sun Nov 27, 2005 2:33 pm   Post subject: (No subject)

Dont you need two of these commands, 1 for " ", and other for "-"? Also, mind telling me the stringSplit command in Java? Thanks a lot Smile
Hikaru79




PostPosted: Sun Nov 27, 2005 2:54 pm   Post subject: (No subject)

MysticVegeta wrote:
Dont you need two of these commands, 1 for " ", and other for "-"?

Nope Smile The second parameter is optional, but if you give it, it treats every single character in the string as a delimiter. No need to tokenize the tokens twice, that would just be painful. StringTokenizer is a powerful tool, I think I use it on just about every contest I've ever written.

MysticVegeta wrote:
Also, mind telling me the stringSplit command in Java? Thanks a lot Smile

I've never heard of a stringSplit method, sorry Sad
Cervantes




PostPosted: Sun Nov 27, 2005 3:16 pm   Post subject: (No subject)

MysticVegeta wrote:
Dont you need two of these commands, 1 for " ", and other for "-"?

Notice that the parameter he passed in contained two characters: a space and a hyphen. I assume that it would tokenize the string based on every character in that string parameter. Seems to me that it would make more sense if it passed in an array of characters. That would also give more flexibility: you could tokenize the string at space, hyphen, and a double hyphen.
MysticVegeta




PostPosted: Sun Nov 27, 2005 3:25 pm   Post subject: (No subject)

Yeah I noticed it before posting too but then I thought about it and thought that since "-" and " " form 1 string, maybe it would tokenize the part where it would find " -". If it does otherwise, how can we tokenize a string with more than 1 character?
Hikaru79




PostPosted: Sun Nov 27, 2005 4:41 pm   Post subject: (No subject)

Cervantes wrote:
MysticVegeta wrote:
Dont you need two of these commands, 1 for " ", and other for "-"?

Notice that the parameter he passed in contained two characters: a space and a hyphen. I assume that it would tokenize the string based on every character in that string parameter. Seems to me that it would make more sense if it passed in an array of characters. That would also give more flexibility: you could tokenize the string at space, hyphen, and a double hyphen.


Hmm, that's an excellent idea. I don't know why Sun never thought of that.

Perhaps I'll make a class Extending StringTokenizer which can do just that Very Happy
Display posts from previous:   
   Index -> CompSci.ca, Contests -> DWITE
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

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


Style:  
Search: