Document directory
- To commemorate the first TC question... The format is really cool and not used
- Problem Statement
- Definition
- Constraints
- Examples
To commemorate the first TC question... The format is really tough, and it's not used to problem statement. |
|
You are given a simpleParagraphContaining a number of sentences, the original person who wrote the paragraph was in a rush and used only lower case letters ('A'-'Z ') for the words in the paragraph and did not use any punctuation other than a period to separate sentences. your task is to fix the capitalization in the paragraph, the objective is to make it so every sentence in the paragraph begins with a capital (upper case) letter ('A'-'Z '). TheParagraphIs formatted as one or more sentences separated by single space ('') characters. each sentence consists of one or more words separated by single space ('') characters. the last word in a sentence is always immediately followed by a single dot ('. ') character. each word is a non-empty string containing only lower case letters ('A'-'Z '). as an example, consider the following paragraph (quotes for clarity ): "this is merely an example. be careful. this is a new sentence." The result of your program must then be as follows: "This is merely an example. Be careful. This is a new sentence." |
Definition |
|
Class: |
Sentencecapitalizerinator |
Method: |
Fixcaps |
Parameters: |
String |
Returns: |
String |
Method signature: |
String fixcaps (string paragraph) |
(Be sure your method is public) |
|
|
|
Constraints |
- |
ParagraphWill contain between 2 and 50 characters, inclusive. |
- |
Each character inParagraphWill be a lower case letter ('A'-'Z'), a space ('') or a dot ('.'). |
- |
The first characterParagraphWill be a lower case letter ('A'-'Z '). |
- |
The last characterParagraphWill be a dot ('.'). |
- |
There will be no two consecutive space characters inParagraph. |
- |
Every space ('') character inParagraphWill precede a letter. |
- |
Every'. 'character inParagraphCannot the last one will precede a space character. |
Examples |
0) |
|
|
"hello programmer. welcome to topcoder." |
|
Returns: "Hello programmer. Welcome to topcoder." |
|
|
1) |
|
|
|
Returns: "One." |
A sentence can consist of just a single word. |
|
|
2) |
|
|
"not really. english. qwertyuio. a. xyz." |
|
Returns: "Not really. English. Qwertyuio. A. Xyz." |
|
|
3) |
|
|
"example four. the long fourth example. a. b. c. d." |
|
Returns: "Example four. The long fourth example. A. B. C. D." |
|
|
# Include <vector> <br/> # include <string> <br/> # include <list> <br/> # include <map> <br/> # include <set> <br/> # include <deque> <br/> # include <stack> <br/> # include <bitset> <br/> # include <algorithm> <br/> # include <functional> <br/> # include <numeric> <br/> # include <utility> <br/> # include <sstream> <br/> # include <iostream> <br/> # include <iomanip> <br/> # include <cstdio> <br/> # include <cmath> <br/> # include <Cstdlib> <br/> # include <ctime> </P> <p> using namespace STD; </P> <p> class sentencecapitalizerinator {<br/> public: <br/> string fixcaps (string paragraph) <br/> {<br/> paragraph [0] = paragraph [0]-32; <br/> int I = 1; <br/> while (I <Paragraph. size () <br/>{< br/> If (paragraph [I] = '. '& I! = Paragraph. size ()-1) <br/>{< br/> I ++; <br/> I ++; <br/> paragraph [I] = paragraph [I]-32; <br/>}< br/> I ++; <br/>}< br/> return paragraph; <br/>}< br/>}; <br/>