Files
python/TangDou/LuoGuBook/P1098_0.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

54 lines
2.2 KiB
C++
Raw Permalink 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 <bits/stdc++.h>
using namespace std;
//批量输出某个字符
void print(char c, int cnt) {
for (int i = 1; i <= cnt; i++) cout << c;
}
int main() {
int p1; //大写小写还是星号 1:小写 2大写 3星号
int p2; //个数 连续填充的个数
int p3; //是否改为逆序p3=1表示维持原来顺序p_3=2表示采用逆序输出
string s;
cin >> p1 >> p2 >> p3 >> s;
//找到所有的-号
for (int i = 0; i < s.size(); i++) {
//遇到下面的情况需要做字符串的展开:在输入的字符串中,
// 出现了减号“-”减号两侧同为小写字母或同为数字且按照ASCII码的顺序
// 减号右边的字符严格大于左边的字符
if (s[i] == '-' && ((isdigit(s[i - 1]) && isdigit(s[i + 1])) || (isalpha(s[i - 1]) && isalpha(s[i + 1])))) {
//减号右边的字符严格大于左边的字符
if (s[i - 1] < s[i + 1]) {
//输出*号
if (p1 == 3) // p_1=3时不论是字母子串还是数字字串
// 都用与要填充的字母个数相同的星号“*”来填充。
//注意填充的字符是两边不咬~
for (char a = s[i - 1] + 1; a < s[i + 1]; a++) print('*', p2);
//小写
if (p1 == 1) {
if (p3 == 1) //原序
for (char a = s[i - 1] + 1; a < s[i + 1]; a++) print(tolower(a), p2);
else //倒序
for (char a = s[i + 1] - 1; a > s[i - 1]; a--) print(tolower(a), p2);
}
//大写
if (p1 == 2) {
if (p3 == 1) //原序
for (char a = s[i - 1] + 1; a < s[i + 1]; a++) print(toupper(a), p2);
else //倒序
for (char a = s[i + 1] - 1; a > s[i - 1]; a--) print(toupper(a), p2);
}
} //否则给啥就输出啥
else
print(s[i], 1);
}
//输出正常的字符
else
print(s[i], 1);
}
return 0;
}