일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 운영체제
- Generator
- iterator
- Python Implementation
- DWG
- shiba
- LeetCode
- 715. Range Module
- attribute
- Python Code
- Convert Sorted List to Binary Search Tree
- 컴퓨터의 구조
- concurrency
- Regular Expression
- 시바견
- Decorator
- Class
- 30. Substring with Concatenation of All Words
- 프로그래머스
- Python
- Substring with Concatenation of All Words
- Protocol
- 109. Convert Sorted List to Binary Search Tree
- data science
- kaggle
- 파이썬
- 밴픽
- t1
- 43. Multiply Strings
- 315. Count of Smaller Numbers After Self
Archives
- Today
- Total
Scribbling
[C++] Regular Expression Matching 본문
C++ Regular Expressions Library
https://en.cppreference.com/w/cpp/regex
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 |