r/dailyprogrammer • u/oskar_s • Apr 25 '12
[4/25/2012] Challenge #44 [easy]
Write a program that divides up some input text into sentences and then determines which sentence in the input has the most words. Print out the sentence with the most words and the number of words that are in it. Optionally, also print out all words in that sentence that are longer than 4 characters.
Sentences can end in periods, exclamation points and question marks, but not colons or semi-colons.
If you need something to input, try Shylock's famous speech from Shakespeare's The Merchant of Venice:
If it will feed nothing else, it will feed my revenge. He hath disgrac'd me and hind'red me half a million; laugh'd at my losses, mock'd at my gains, scorned my nation, thwarted my bargains, cooled my friends, heated mine enemies. And what's his reason? I am a Jew. Hath not a Jew eyes? Hath not a Jew hands, organs, dimensions, senses, affections, passions, fed with the same food, hurt with the same weapons, subject to the same diseases, healed by the same means, warmed and cooled by the same winter and summer, as a Christian is? If you prick us, do we not bleed? If you tickle us, do we not laugh? If you poison us, do we not die? And if you wrong us, shall we not revenge? If we are like you in the rest, we will resemble you in that. If a Jew wrong a Christian, what is his humility? Revenge. If a Christian wrong a Jew, what should his sufferance be by Christian example? Why, revenge. The villainy you teach me I will execute; and it shall go hard but I will better the instruction.
- Thanks to frenulem for submitting this problem to /r/dailyprogrammer_ideas! Do you have a problem that you think would be good for this subreddit? Head on over there and suggest it!
5
u/[deleted] Apr 25 '12
PHP / HTML : Live Preview
1
u/robin-gvx 0 2 Apr 27 '12
Déjà Vu: http://hastebin.com/raw/gumoyuqiko
3
u/kurogane765 Apr 25 '12 edited Apr 25 '12
python:
optional bonus:
3
u/oneITguy Apr 25 '12
Here is my try in java:
3
u/sanitizeyourhands Apr 25 '12 edited Apr 25 '12
C#:
2
u/ixid 0 0 Apr 25 '12 edited Apr 25 '12
D language
2
u/lorad Apr 26 '12
C#
2
u/scribblingmaniac Apr 26 '12
Haxe / Neko / C++
2
u/Intolerable Apr 26 '12
1
u/[deleted] Apr 25 '12
an a bit too improvised python. Also missing character from the sentence's end
1
u/[deleted] Apr 25 '12
common lisp, not the best language for this problem:
usage: (tally "phrase")
1
u/magwhich Apr 25 '12
python
1
u/GuitaringEgg Apr 25 '12
Python:
1
u/[deleted] Apr 26 '12 edited Apr 26 '12
Perl
ADD FOR BONUS
1
u/HazzyPls 0 0 Apr 26 '12
Just learned about strtok and strok_r today! So excited that I get to use them.
1
u/jaspeh Apr 26 '12 edited Apr 26 '12
C#
Made sure not to include commas and other characters when check for word length.
1
u/Devanon Apr 26 '12
Ruby:
1
u/exor674 Apr 26 '12 edited Apr 27 '12
C++11:
1
u/stereopump 0 0 Apr 27 '12
My solution isn't very clean, but here it is anyways.
Would someone mind telling me why my code is so much longer? Thanks.
1
u/chriszimort Apr 27 '12
C# function:
1
u/jfrios 0 0 Apr 27 '12 edited Apr 27 '12
python:
1
u/Nedroo Apr 28 '12
Scala
1
u/[deleted] May 04 '12
JavaScript. Works well
1
u/singingtoast May 07 '12
Here was my attempt in Java. I'm fairly new and am wondering why this does not work.
public class Sort { public static String sort(String a) { String tempA = ""; String tempB = ""; for (int i =0; i <= a.length(); i++) { int beg = 0; char x = a.charAt(i); String y = Character.toString(x); if (y=="." || y=="?" || y=="!") {
}
1
u/bigronaldo May 31 '12
Another C# solution. Takes an average of 10ms to parse a string with 2501 sentences, 68,210 words, and 433,708 characters.
1
u/Should_I_say_this Jul 03 '12
Bonus:
1
u/scribblingmaniac Apr 26 '12
Haxe / Neko / C++ using StringTools;
0
u/[deleted] Apr 25 '12
[deleted] — view deleted comment
0
u/[deleted] Apr 25 '12
[deleted] — view deleted comment