From 12e18ec4154db36c350a12836e3db198a37db584 Mon Sep 17 00:00:00 2001 From: flykhan Date: Fri, 16 Jun 2023 09:15:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=97=E7=AC=A6=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +++-- day4/d12.cpp | 24 ++++++++++++++++++++++++ day4/d13.cpp | 24 ++++++++++++++++++++++++ day4/exercise_2.4.5.2.cpp | 12 ++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 day4/d12.cpp create mode 100644 day4/d13.cpp create mode 100644 day4/exercise_2.4.5.2.cpp diff --git a/.gitignore b/.gitignore index c9a224c..74779ba 100644 --- a/.gitignore +++ b/.gitignore @@ -86,9 +86,10 @@ Module.symvers Mkfile.old dkms.conf -# 自定义 +# 自定义过滤 */output *.i *.s *.o -*.swp \ No newline at end of file +*.swp +.vscode \ No newline at end of file diff --git a/day4/d12.cpp b/day4/d12.cpp new file mode 100644 index 0000000..22f59ac --- /dev/null +++ b/day4/d12.cpp @@ -0,0 +1,24 @@ +#include +#include // 引入正则表达式库 + +using namespace std; + +int main() +{ + string x; + cout << "输入一个字符:" << endl; + cin >> x; + + regex regex_lower("[a-z]"); + regex regex_upper("[A-Z]"); + cout << regex_match(x, regex_lower) << regex_match(x, regex_upper) << endl; + // 正则表达式 + if (regex_match(x, regex_lower)) // regex_match 匹配正则表达式 + { + cout << (char)(x.at(0) - 32) << endl; // .at(0) 获取第一个字符 + } + else if (regex_match(x, regex_upper)) + { + cout << (char)(x.at(0) + 32) << endl; + } +} \ No newline at end of file diff --git a/day4/d13.cpp b/day4/d13.cpp new file mode 100644 index 0000000..561b3c8 --- /dev/null +++ b/day4/d13.cpp @@ -0,0 +1,24 @@ +#include +#include + +using namespace std; + +int main() +{ + // 字符串打印遇到\0则结束打印 + string str1 = "abc\0good"; // abc\0good\0 + cout << str1 << str1 << endl; + cout << "sizeof str1 = " << sizeof(str1) << endl; // 32B 32*8=256位 + + char str2[] = "disen666"; // 字符数组, 实际上也是一个字符串 + cout << "str2 = " << str2 << endl; + + char str3[] = {'d', 'i', 's', 'e', 'n'}; // 自动添加 '\0' + cout << "str3 = " << str3 << endl; + cout << "sizeof str3 = " << sizeof(str3) << endl; // 5B, 没算 '\0' + + string str4 = "a"; + cout << "sizeof str4 = " << sizeof(str4) << endl; // 32B 32*8=256位 + + return 0; +} diff --git a/day4/exercise_2.4.5.2.cpp b/day4/exercise_2.4.5.2.cpp new file mode 100644 index 0000000..241c3a9 --- /dev/null +++ b/day4/exercise_2.4.5.2.cpp @@ -0,0 +1,12 @@ +#include + +using namespace std; + +int main() +{ + int a, b; + cout << "输入两个数:" << endl; + cin >> a >> b; + cout << "最大值为: " << (a > b ? a : b) << endl; + return 0; +} \ No newline at end of file