求调QwQ

P1098 [NOIP2007 提高组] 字符串的展开

```cpp #include <bits/stdc++.h> using namespace std; int p1, p2, p3; string s; void init() { cin >> p1 >> p2 >> p3; cin >> s; } inline bool check(int u) { if ((islower(s[u-1]) && islower(s[u+1])) || (isdigit(s[u-1]) && isdigit(s[u+1]))) { if (s[u-1] < s[u+1]) { return true; } } return false; } int main() { init(); string result; int i = 0; while (i < s.length()) { if (s[i] == '-') { if (check(i)) { char start = s[i-1]; char end = s[i+1]; string t = ""; for (char j = start + 1; j < end; ++j) { char ch = j; if (p1 == 1 || p1 == 2) { if (p1 == 2) ch = toupper(ch); for (int k = 0; k < p2; ++k) t.push_back(ch); } else if (p1 == 3) { for (int k = 0; k < p2; ++k) t.push_back('*'); } } if (p3 == 2) reverse(t.begin(), t.end()); result += t + s[i+1];//s[i-1] 已经加了一次 ++i; } else { result += '-'; } } else { result += s[i]; } ++i; } cout << result << endl; return 0; } ``` @[Yaoshui_lv](/user/1277657)
by qw0er2ty1ui3 @ 2024-09-08 14:20:58


@[qw0er2ty1ui3](/user/1286983) thanks
by Yaoshui_lv @ 2024-09-08 14:28:05


|