TopCoder problem "Cyberline" used in SRM 187 (Division I Level One)



Problem Statement

    

As managing editor of BadCyberPoetry.net you find to your dismay that you must follow through on your threat to replace your "Editor of Conventionally Structured Poetry" with a very small shell script (or something to that effect).

The first part of this project is to build a method that returns the last cyberword of a cyberline of cybertext, in a form that is convenient for rhyme testing. Since this is bad cyber poetry, words may contain symbols other than letters.

A "cyberword" may contain letters, numbers, the hyphen (minus) character '-' and the '@' character (quotes for clarity). Cyberwords must contain at least one character that is a letter, number or '@'. Isolated hyphens or strings of hyphens alone are not cyberwords. Any other character is considered punctuation or white space and causes a cyberword break.

Cyberlines may contain cyberwords, punctuation, and spaces in any order, so the last cyberword may not be at the end of the cyberline. The cyberword you return should have all hyphens removed to simplify rhyme testing.

For example: In the string "Zowie: This is a line of##cyber-poetry## !",

"cyberpoetry" is returned.

 

Definition

    
Class:Cyberline
Method:lastCyberword
Parameters:String
Returns:String
Method signature:String lastCyberword(String cyberline)
(be sure your method is public)
    
 

Constraints

-cyberline will consist of between 1 and 50 characters inclusive.
-cyberline consists of letters ('a'-'z' and 'A'-'Z'), digits ('0'-'9'), the space character and ".,()?!<>#&$%_=+;:/~|{}-@" (quotes for clarity) in any order.
-cyberline will contain at least one character which is a letter ('a'-'z' or 'A'-'Z'), digit ('0'-'9'), or '@'
 

Examples

0)
    
"Zowie: This is a line of##cyber-poetry## !"
Returns: "cyberpoetry"
This is the example from above.
1)
    
"2-b|!2-b -- ?"
Returns: "2b"
2)
    
"if then{}; elseif schmelshif();"
Returns: "schmelshif"
3)
    
"~y?"
Returns: "y"
4)
    
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
Returns: "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=2396

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4755&pm=2396

Writer:

Rustyoldman

Testers:

lbackstrom , brett1479

Problem categories:

String Parsing