728x90 Regex4 [programmers] Lv.3 불량 사용자(c++) 더보기 #include #include #include #include using namespace std; set answer; void find_all(vector& ban_possible, set banned = {}, int i=0){ for(auto possible: ban_possible[i]){ if(banned.find(possible) != banned.end()) continue; else banned.insert(possible); if(i+1 != ban_possible.size()) find_all(ban_possible, banned, i+1); if(i+1 == ban_possible.size() && banned.size() == ban_possible.size()) { an.. 2022. 5. 4. [programmers] Lv.2 튜플(c++) 간단하게 끝낼 수 있는것은 간단하게 해결하자!! 는 생각이었다. 더보기 #include #include #include using namespace std; vector split(string str){ smatch match; vector res; while(regex_search(str, match, regex("(\\d|,)+"))){ string matched = match.str(); str = match.suffix().str(); str = str.substr(2); smatch number; vector inside; while(regex_search(matched, number, regex("\\d+"))){ inside.push_back(stoi(number.str())); matche.. 2022. 5. 4. [programmers] Lv.2 수식 최대화(c++) 처음엔 정규표현식을 사용해 숫자 연산자 숫자를 찾아 계산하고싶었다. (너무 어렵게 생각한것같음) 예시는 통과했지만, 대부분의 tc는 통과하지 못했다. 아직 이유를 파악하지 못했다... 더보기 #include #include #include using namespace std; string add(string str){ smatch match; while(regex_search(str, match, regex("(\\d+[+](-)?\\d+)|(^(-)\\d+[+](-)?\\d+)"))){ long long a, b; sscanf(match.str().c_str(), "%lld+%lld", &a, &b); str.replace(str.find(match.str()), match.str().length(),.. 2022. 5. 1. [programmers] Lv.1 숫자 문자열과 영단어(c++) regex를 알게됨 아래 코드는 regex_replace를 알기 전 코드이다. 역시나 for문을 한번만 돌기위해 애씀 더보기 #include using namespace std; int solution(string s) { vector nums = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; string answer; for(int i=0; i 2022. 3. 8. 이전 1 다음 728x90