第一题

This commit is contained in:
2025-06-16 20:36:36 +08:00
commit 52fbb75553
5 changed files with 81 additions and 0 deletions

View File

@ -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 <iostream>
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;
}