From 52fbb7555309593fadce07ae0f78684c6be51ac1 Mon Sep 17 00:00:00 2001 From: Sherlock <1297399478@qq.com> Date: Mon, 16 Jun 2025 20:36:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ CMakeLists.txt | 9 ++++++ Solving/Questions.h | 7 +++++ Solving/StringSegmentation.cpp | 57 ++++++++++++++++++++++++++++++++++ main.cpp | 6 ++++ 5 files changed, 81 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 Solving/Questions.h create mode 100644 Solving/StringSegmentation.cpp create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c89c799 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +build_C/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a4b9bf5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.28) +project(lico) + +include_directories(Solving) +aux_source_directory(Solving SOL_LIST) + +set(CMAKE_CXX_STANDARD 11) + +add_executable(lico main.cpp ${SOL_LIST}) diff --git a/Solving/Questions.h b/Solving/Questions.h new file mode 100644 index 0000000..02f8054 --- /dev/null +++ b/Solving/Questions.h @@ -0,0 +1,7 @@ +#ifndef LICO_QUESTIONS_H +#define LICO_QUESTIONS_H + +//1、字符串分割 +void StringSegmentation(); + +#endif //LICO_QUESTIONS_H diff --git a/Solving/StringSegmentation.cpp b/Solving/StringSegmentation.cpp new file mode 100644 index 0000000..1dbbbee --- /dev/null +++ b/Solving/StringSegmentation.cpp @@ -0,0 +1,57 @@ +#include "Questions.h" + +/** +给定一个非空字符串S,其被N个‘-’分隔成N+1的子串,给定正整数K,要求除第一个子串外, +其余的子串每K个字符组成新的子串,并用‘-’分隔。对于新组成的每一个子串,如果它含有的 +小写字母比大写字母多,则将这个子串的所有大写字母转换为小写字母;反之,如果它含有的 +大写字母比小写字母多,则将这个子串的所有小写字母转换为大写字母;大小写字母的数量相等时,不做转换。 +输入描述: +输入为两行,第一行为参数K,第二行为字符串S。 +输出描述: +输出转换后的字符串。 +示例1 +输入 +3 +12abc-abCABc-4aB@ +输出 +12abc-abc-ABC-4aB-@ + */ +#include + +void StringSegmentation() { + std::string inputStr; + int inputNmb; + std::cin >> inputNmb; + std::cin >> inputStr; + + std::string output; + int index = inputStr.find('-'); + if (index == -1) { + return; + } + output = std::string(inputStr.begin(), inputStr.begin() + index + 1); + inputStr = inputStr.substr(index + 1); + std::string tmpStr{}; + index = inputStr.find('-'); + while (index != -1) { + tmpStr += inputStr.substr(0, index); + inputStr = inputStr.substr(index + 1); + index = inputStr.find('-'); + } + tmpStr += inputStr; + for (auto i: tmpStr) { + int low{}, up{}, cnt{}; + std::string lowStr = "-"; + std::string upStr = "-"; + if (i >= 'a' && i <= 'z') { + ++low; + lowStr.push_back(i); + upStr.push_back(i + 26); + } + else if (i >= 'A' && i <= 'z') + } + + + + std::cout << output; +} diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..28a6fd9 --- /dev/null +++ b/main.cpp @@ -0,0 +1,6 @@ +#include "Questions.h" + +int main() { + StringSegmentation(); + return 0; +}