var lines :string var numbers :array1.. 5ofint 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 endif endfor result count + 1 end wordCount
proc errors
for x :1.. 5
numbers (x):=strint(syl (x)) - numbers (x) if numbers (x)not= 0then
current :=abs(numbers (x)) if current > high then
original := numbers (x)
high := current
lineno := x
endif endif endfor end errors
for s :1.. 5 for x :1.. 5 get: fi, lines :*
numbers (x):= wordCount (lines) endfor
errors
ifabs(original)= original then put: fo, "LINE ", lineno, " - ", original, " SYLLABLE(S) TOO FEW" else put: fo, "LINE ", lineno, " - ",abs(original)," SYLLABLE(S) TOO MANY" endif
lineno :=0
original :=0
current :=0
high :=0 endfor 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
Cervantes
Posted: 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
Posted: 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,
and the whole question just falls apart When you're on a timed contest, this sort of thing is great.
Sponsor Sponsor
MysticVegeta
Posted: 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
Posted: 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
MysticVegeta
Posted: 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
Hikaru79
Posted: 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 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
I've never heard of a stringSplit method, sorry
Cervantes
Posted: 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
Posted: 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
Posted: 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