TopCoder problem "SecretOffer" used in SRM 26 (Division I Level Three , Division II Level Three)



Problem Statement

    
Class name: SecretOffer
Method name: translate
Parameters: String
Returns: long


A secretive group wants to make offers through email in a way that will be
difficult to distinguish from normal email traffic.  The offer consists of a
single integer value.


Here is the method signature (Be sure your method is public):
long translate(String message)


The value is described in terms of the names of its digits (zero, one, two,
three, four, five, six, seven, eight, nine).  The characters of these names are
scattered throughout the message in order.  The first digit in the value is the
first digit completed in the message (a digit is completed when all its
characters have occurred in the message in order ignoring case).


No digit may re-use an individual character that is used by another digit.


Each digit always considers the first possible character that can be the next
letter in its name. (ie: "fisivex" translates to 56, never to just 5).


In the case that a single character completes two different digits, the smaller
digit takes precedence.  For example, the second 'e' in "thorenee" finishes
both "one" and "three".  Because 1 < 3, the second e is used to finish the
digit one.  The third and final e is used to finish the digit "three" and the
return value for "thorenee" is 13.


INPUT:
A string of length between 1 and 50, inclusive, containing letters (a-z, A-Z),
and/or spaces.

OUTPUT:
The sum of the message (as a long).  If no digits are found, return 0.  Ignore
any leading zeros.


EXAMPLES:


Input:  "The Final Fantasy movie is now in theaters"


1st digit: five Fi(nal Fantasy mo)v(i)e(...)
leaving "The nal Fantasy moi is now in theaters"


2nd digit: one (T...m)o(i is )n(ow in th)e(...)
leaving "The nal Fantasy mi is ow in thaters"


3rd digit: one (T...s )o(w i)n( that)e(...)
leaving "The nal Fantasy mi is w i thatrs"


No more ordered digits remain in the String, so we have digits 5, 1, 1.i


Output: 511


Input:  "Summer has been very dull and lifeless this year"
Output: 7


Input:  "Nit picking again eh Obiwan Kenobi"
Output: 912


Input:  "evif"
Output: 0


Input:  "threfive"
Output: 3


Input:  "nineight"
Output: 9

 

Definition

    
Class:SecretOffer
Method:translate
Parameters:String
Returns:long
Method signature:long translate(String param0)
(be sure your method is public)
    

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=3025&pm=152

Writer:

Soli

Testers:

Problem categories: