P1098 [NOIP2007 提高组] 字符串的展开(总结)
P1098 [NOIP2007 提高组] 字符串的展开http://ww.luogu.com.cn/problem/P1098
注意
字符中的数字是默认小于字母的。
所以要对数字做特判。
#include <iostream>
#include <string>
using namespace std;
int main() {
int p1, p2, p3;
cin >> p1 >> p2 >> p3;
string s;
cin >> s;
char start, stop;
for (int i = 0; i < s.length(); i++) {
cout << s[i];
if (s[i + 1] == '-') {
if ((s[i] < s[i + 2] - 1 && '0' <= s[i] && s[i] <= '9' && '0' <= s[i] && s[i + 2] <= '9') || (s[i] < s[i + 2] - 1
&& 'a' <= s[i] && s[i] <= 'z'
&& 'a' <= s[i + 2] && s[i + 2] <= 'z')) {
if (p1 == 1) {
if (p3 == 1) {
start = s[i] + 1;
stop = s[i + 2] - 1;
while (start <= stop) {
for (int j = 1; j <= p2; j++) {
cout << start;
}
start++;
}
i++;
} else {
start = s[i] + 1;
stop = s[i + 2] - 1;
while (start <= stop) {
for (int j = 1; j <= p2; j++) {
cout << stop;
}
stop--;
}
i++;
}
} else if (p1 == 2) {
if (s[i] < 'a') {
if (p3 == 1) {
start = s[i] + 1;
stop = s[i + 2] - 1;
while (start <= stop) {
for (int j = 1; j <= p2; j++) {
cout << start;
}
start++;
}
i++;
} else {
start = s[i] + 1;
stop = s[i + 2] - 1;
while (start <= stop) {
for (int j = 1; j <= p2; j++) {
cout << stop;
}
stop--;
}
i++;
}
} else {
if (p3 == 1) {
start = s[i] - 'a' + 'A' + 1;
stop = s[i + 2] - 'a' + 'A' - 1;
while (start <= stop) {
for (int j = 1; j <= p2; j++) {
cout << start;
}
start++;
}
i++;
} else {
start = s[i] - 'a' + 'A' + 1;
stop = s[i + 2] - 'a' + 'A' - 1;
while (start <= stop) {
for (int j = 1; j <= p2; j++) {
cout << stop;
}
stop--;
}
i++;
}
}
} else {
if (p3 == 1) {
start = s[i] + 1;
stop = s[i + 2] - 1;
while (start <= stop) {
for (int j = 1; j <= p2; j++) {
cout << '*';
}
start++;
}
i++;
} else {
start = s[i] + 1;
stop = s[i + 2] - 1;
while (start <= stop) {
for (int j = 1; j <= p2; j++) {
cout << '*';
}
stop--;
}
i++;
}
}
} else if (s[i] == s[i + 2] - 1 ) {
i++;
}
}
}
}