728x90
์ ๋ ฅ ๋ฐ์ ์์ด์ ์ซ์๊ฐ ์กฐํฉ๋ ๋ฌธ์์ด์์ ํ๋ํ๋ ๋น๊ต๋ฅผ ํตํด case๋ฅผ ๋ง๋ค์๋ค. ์์ด ๋ฌธ์์ด์ด ๋์ค๋ ๊ฒฝ์ฐ ์ ํด์ง ๋จ์ด์ ๊ธธ์ด๋ฅผ ์๊ฐํด์ one ๋ถํฐ nine๊น์ง๋ฅผ ๋ถ๋ฅํ๋ค.
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int solution(string s) {
int answer = 0;
string arr = "";
for(int i = 0 ; i < s.size() ; i++) {
if(s[i] >= '0' && s[i] <= '9') {
arr.push_back(s[i]);
continue;
}
if(s[i] == 'z' && s.substr(i,4) == "zero") {
arr.push_back('0');
i = i + 3;
}
else if(s[i] == 'o' && s.substr(i,3) == "one") {
arr.push_back('1');
i = i + 2;
}
else if(s[i] == 't' && s.substr(i,3) == "two") {
arr.push_back('2');
i = i + 2;
}
else if(s[i] == 't' && s.substr(i,5) == "three") {
arr.push_back('3');
i = i + 4;
}
else if(s[i] == 'f' && s.substr(i,4) == "four") {
arr.push_back('4');
i = i + 3;
}
else if(s[i] == 'f' && s.substr(i,4) == "five") {
arr.push_back('5');
i = i + 3;
}
else if(s[i] == 's' && s.substr(i,3) == "six") {
arr.push_back('6');
i = i + 2;
}
else if(s[i] == 's' && s.substr(i,5) == "seven") {
arr.push_back('7');
i = i + 4;
}
else if(s[i] == 'e' && s.substr(i,5) == "eight") {
arr.push_back('8');
i = i + 4;
}
else if(s[i] == 'n' && s.substr(i,4) == "nine") {
arr.push_back('9');
i = i + 3;
}
else continue;
}
answer = stoi(arr);
cout << arr << endl;
return answer;
}