Files
lico/Solving/StringSegmentation.cpp
2025-06-16 20:36:36 +08:00

58 lines
1.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}