Notice
Recent Posts
Recent Comments
- Today
- Total
01-26 23:33
Tags
- ๊ทธ๋ฆฌ๋
- dp
- database
- PS
- BFS
- Graph
- Algorithm
- ํ๋ก๊ทธ๋๋จธ์ค
- pytorch
- ๋ฐฑ์ค
- CS
- ๋ฌธ๋ฒ
- ๋ฒจ๋งํฌ๋
- ์กธ์ ์ํ
- ๋ค์ต์คํธ๋ผ
- leetcode
- array
- ๊ตฌํ
- ์์์ ๋ ฌ
- tree
- ์๋ฐ
- java
- ์ธํด
- OOP
- ์๋ฐ์์ ์
- spring
- ๋ฐ์ดํฐ๋ฒ ์ด์ค
- ๋ฐฑ์๋
- MST
- ์๋ฃ๊ตฌ์กฐ
Link
Partially Committed
[2021 ์นด์นด์ค ์ฑ์ฉ์ฐ๊ณํ ์ธํด์ญ] ์ซ์ ๋ฌธ์์ด๊ณผ ์๋จ์ด ๋ณธ๋ฌธ
๐ฅ Algorithm || ๋ฌธ์ ํ์ด/PS
[2021 ์นด์นด์ค ์ฑ์ฉ์ฐ๊ณํ ์ธํด์ญ] ์ซ์ ๋ฌธ์์ด๊ณผ ์๋จ์ด
WonderJay 2022. 6. 28. 12:07728x90
๋ฐ์ํ
SMALL
https://programmers.co.kr/learn/courses/30/lessons/81301
์ ๊ด๊ณ๋ฅผ Key(์ซ์) - value(์๋จ์ด) ๋ผ๊ณ ์๊ฐํ๊ณ map ์ ์ ์ฅํ๋ค.
string s ๋ฅผ ์ํํ๋๋ฐ, digit ์ด๋ฉด answer ์ push_back ํด์ฃผ๊ณ ,
digit ์ด ์๋๋ฉด temp ์ ์ ์ฅํ๋ค.
๊ทธ๋ฆฌ๊ณ temp ์ map ์ value ๋ฅผ ๋น๊ตํด์ ์ผ์นํ๋ค๋ฉด key ๊ฐ์ ans ์ push_back ํด์ฃผ๋ฉด ๋๋ค.
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
int solution(string s) {
int answer = 0;
unordered_map <string, string> table;
table.insert(make_pair("0", "zero"));
table.insert(make_pair("1", "one"));
table.insert(make_pair("2", "two"));
table.insert(make_pair("3", "three"));
table.insert(make_pair("4", "four"));
table.insert(make_pair("5", "five"));
table.insert(make_pair("6", "six"));
table.insert(make_pair("7", "seven"));
table.insert(make_pair("8", "eight"));
table.insert(make_pair("9", "nine"));
string ans = ""; string temp = "";
for (char& c : s)
{
if (isdigit(c))
{
ans.push_back(c);
}
else
{
temp.push_back(c);
for (auto& i : table)
{
if (temp == i.second)
{
ans.append(i.first);
temp.clear();
break;
}
}
}
}
answer = stoi(ans);
return answer;
}
728x90
๋ฐ์ํ
LIST
'๐ฅ Algorithm || ๋ฌธ์ ํ์ด > PS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] ํฌ๋ ์ธ ์ธํ๋ฝ๊ธฐ ๊ฒ์ (0) | 2022.07.01 |
---|---|
[2020 ์นด์นด์ค ์ธํด์ญ] ํคํจ๋ ๋๋ฅด๊ธฐ (0) | 2022.06.29 |
[2021 KAKAO BLIND RECRUITMENT] ์ ๊ท ์์ด๋ ์ถ์ฒ (0) | 2022.06.28 |
[2022 KAKAO BLIND RECRUITMENT] ์ ๊ณ ๊ฒฐ๊ณผ๋ฐ๊ธฐ (0) | 2022.06.26 |
[c++]Associate container (0) | 2022.06.25 |
Comments