-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f362672
commit a39cef8
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <string> | ||
#include <vector> | ||
#include <unordered_map> | ||
|
||
using namespace std; | ||
|
||
long long solution(string numbers) { | ||
long long answer = 0; | ||
unordered_map<string, int> m = { | ||
{"zero", 0}, | ||
{"one", 1}, | ||
{"two", 2}, | ||
{"three", 3}, | ||
{"four", 4}, | ||
{"five", 5}, | ||
{"six", 6}, | ||
{"seven", 7}, | ||
{"eight", 8}, | ||
{"nine", 9}, | ||
}; | ||
|
||
string temp = ""; | ||
for (char c : numbers) { | ||
temp += c; | ||
|
||
if (m.count(temp) > 0) { | ||
answer = answer * 10 + m[temp]; | ||
temp = ""; | ||
} | ||
} | ||
|
||
return answer; | ||
} |