Calculation of words, sentences and paragraphs from text entered by the user
I need to write a program to take an entry 'essay' from the user. This essay can contain any characters (special characters, quotation marks, etc.). It then has to calculate the total开发者_如何学Go number of words, sentences and paragraphs, and the total number of special characters. How should I go about doing this?
I can't believe you would expect someone to write a program for you, so I am assuming that you are asking the correct way to tackle the problem.
Break the problem down into smaller, manageable problems:
1) Define what a word is (a string of uninterrupted letters)
2) Work out a way of counting those items (e.g. you could start at the beginning of the input, look for how many interruptions to strings of letters there are)
3) Define what a sentence is (a string of words, ended by a period '.')
4) Work out a way of counting those items (e.g. you could count the number of periods preceeded by at least one word)
And so on.
精彩评论