SRM 505 ----score 250

 

纪念下第一道TC题。。。那格式实在很蛋疼,很不习惯

Problem Statement

     You are given a simple paragraph containing 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').

The paragraph is 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

- paragraph will contain between 2 and 50 characters, inclusive.
- Each character in paragraph will be a lower case letter ('a'-'z'), a space (' ') or a dot ('.').
- The first character of paragraph will be a lower case letter ('a'-'z').
- The last character of paragraph will be a dot ('.').
- There will be no two consecutive space characters in paragraph.
- Every space (' ') character in paragraph will precede a letter.
- Every '.' character in paragraph except the last one will precede a space character.

Examples

0)  
    
"hello programmer. welcome to topcoder."
Returns: "Hello programmer. Welcome to topcoder."
 
1)  
    
"one."
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."
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值