提交时间:2023-08-22 21:07:28

运行 ID: 99482

#include <iostream> #include <string> std::string expandString(const std::string& str, int p1, int p2, int p3) { std::string expandedStr; int length = str.length(); for (int i = 0; i < length; ++i) { if (str[i] == '-') { char leftChar = str[i - 1]; char rightChar = str[i + 1]; if ((isdigit(leftChar) && isdigit(rightChar) && rightChar > leftChar) || (islower(leftChar) && islower(rightChar) && rightChar > leftChar)) { char fillChar; if (p1 == 1) { fillChar = 'a'; } else if (p1 == 2) { fillChar = 'A'; } else { fillChar = '*'; } std::string fillStr(p2, fillChar); if (p3 == 2) { for (char j = rightChar - 1; j > leftChar; --j) { expandedStr += std::string(fillStr.size(), j); } } else { for (char j = leftChar + 1; j < rightChar; ++j) { expandedStr += std::string(fillStr.size(), j); } } } else { expandedStr += '-'; } } else { expandedStr += str[i]; } } return expandedStr; } int main() { int p1, p2, p3; std::cin >> p1 >> p2 >> p3; std::string str; std::cin >> str; std::cout << expandString(str, p1, p2, p3) << std::endl; return 0; }