일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 파이썬
- LeetCode
- shiba
- Protocol
- 컴퓨터의 구조
- Regular Expression
- attribute
- 109. Convert Sorted List to Binary Search Tree
- 운영체제
- t1
- Python
- Decorator
- 프로그래머스
- 밴픽
- DWG
- 43. Multiply Strings
- Substring with Concatenation of All Words
- 715. Range Module
- Python Code
- 시바견
- Class
- concurrency
- data science
- kaggle
- Convert Sorted List to Binary Search Tree
- Python Implementation
- 315. Count of Smaller Numbers After Self
- Generator
- 30. Substring with Concatenation of All Words
- iterator
Archives
- Today
- Total
Scribbling
[C++] Regular Expression Matching 본문
C++ Regular Expressions Library
https://en.cppreference.com/w/cpp/regex
Regular expressions library (since C++11) - cppreference.com
Regular expressions library The regular expressions library provides a class that represents regular expressions, which are a kind of mini-language used to perform pattern matching within strings. Almost all operations with regexes can be characterized by
en.cppreference.com
https://leetcode.com/problems/string-to-integer-atoi/description/
#include <iostream>
#include <regex>
#include <stdexcept>
#include <climits>
class Solution {
public:
int myAtoi(string s) {
const std::regex pat("^ *([+-]?)([0-9]+)");
std::smatch match;
std::regex_search(s, match, pat);
if (match.size() == 0) return 0;
string sign = match.str(1);
int parsed;
try {
parsed = stoi(match.str(2));
} catch (std::out_of_range& e) {
if (!sign.empty() and sign == "-")
return INT_MIN;
return INT_MAX;
}
if (!sign.empty() and sign == "-")
return -parsed;
return parsed;
}
};
'Computer Science > C++' 카테고리의 다른 글
[C++] Abstract Class, Polymorphism (0) | 2024.09.28 |
---|---|
[C++] Virtual Functions (0) | 2024.09.28 |
[C++] Priority Queue with custom data type (0) | 2024.02.22 |
[C++] Abstract Class, Interface, Multiple Inheritance (0) | 2024.02.14 |
[C++] lower_bound (0) | 2024.02.06 |