LongLiveZhangzj
SRM 719 · 2017-07-25 · by matthew99a
Problem Statement
Zhangzj is the emperor of Yali empire and is esteemed by his people.
"Long live Zhangzj" is heard across the country. Needless to say, people in the empire hope their leader will live forever. However, everybody will die, unless others donate their lives to the person.
In the empire, there's a special way to donate life. There are some fixed words that are called exciting. Whenever someone speaks an exciting word, he automatically donates one second of his life to Zhangzj. For example, "toad" and "river" are exciting. Then, if somebody says the sequence of words "a", "toad", "jumps", "into", "the", "toad", "river", they donate three seconds to Zhangzj.
Given a
A word may appear multiple times in speech, but not in words.
Constraints
- Both speech and words will contain between 1 and 50 elements, inclusive.
- All pairs of elements in words will be distinct.
- Each element of speech and words will consist only of lowercase English letters.
- The length of each element of speech and words will be between 1 and 50, inclusive.
{"make", "topcoder", "great", "again"}
{"make", "america", "great", "again"}
Returns: 3
"make", "great" and "again" appear in speech and are exciting. Thus, the answer is 3.
{"toads"}
{"toad"}
Returns: 0
The strings "toad" and "toads" are not identical, therefore this speaker does not donate any seconds to Zhangzj.
{"a", "a"}
{"a"}
Returns: 2
Two elements of speech can be the same.
{"je", "le", "ai", "deja", "vu", "et", "je", "le", "veux", "encore"}
{"i", "am", "having", "deja", "vu", "please", "stop", "the", "encore"}
Returns: 3
{"a"}
{"b"}
Returns: 0
Submissions are judged against all 107 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class LongLiveZhangzj with a public method int donate(vector<string> speech, vector<string> words) · 107 test cases · 2 s / 256 MB per case