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