题目链接:https://www.luogu.org/problemnew/show/P1098
这道题目我认为只是步骤较为繁琐,没有什么难度。自己写的时候因为好长时间没有写了。居然把一个判定条件写错了!=_=浪费了好长时间。
#include <stdio.h>
#include <iostream>
using namespace std;
const int MAX_N = 150;
int p1, p2, p3;
char str[MAX_N];
int judge (char str1, char str2) {
// if ((str1 >= 0 && str1 <= 9) && (str2 >= 'a' && str2 <= 'z')) return 1;
// else if ((str2 >= 0 && str2 <= 9) && (str1 >= 'a' && str1 <= 'z')) return 1;
// else return 0;
if ((str1 >= '0' && str2 <= '9' && str2 >= '0' && str2 <= '9') || (str1 >= 'a' && str1 <= 'z' && str2 >= 'a' && str2 <= 'z')) return 0;
else return 1;
}
void solve () {
if (p1 == 1) {
int i = 0;
while (str[i] != '\0') {
if (str[i] == '-') {
if (p3 == 1) {
if (judge (str[i - 1], str[i + 1])) {
cout << "-" << str[i + 1]; i++; //cout << "1" << endl;
}
else if (str[i - 1] >= str[i + 1]) {
cout << "-" << str[i + 1]; i++;
}
else if (str[i - 1] + 1 == str[i + 1]) {
cout << str[i + 1]; i++;
}
else {
int n = str[i - 1] + 1;
int m = p2;
while (n < str[i + 1]) {
for (int j = 1; j <= m; j++) printf ("%c", n);
n++;
}
}
}
else if (p3 == 2) {
if (judge (str[i - 1], str[i + 1])) {
cout << "-" << str[i + 1]; i++;
}
else if (str[i - 1] >= str[i + 1]) {
cout << "-" << str[i + 1]; i++;
}
else if (str[i - 1] + 1 == str[i + 1]) {
cout << str[i + 1];
i ++;
}
else {
int n = str[i + 1] - 1;
int m = p2;
while (n > str[i - 1]) {
for (int j = 1; j <= m; j++) printf ("%c", n);
n--;
}
}
}
i ++;
}
else {
cout << str[i];
i ++;
}
}
}
if (p1 == 2) {
int i = 0;
while (str[i] != '\0') {
if (str[i] == '-') {
if (p3 == 1) {
if (judge (str[i - 1], str[i + 1])) {
cout << "-" << str[i + 1]; i++;
}
else if (str[i - 1] >= str[i + 1]) {
printf ("-%c", str[i + 1]); i++;
}
else if (str[i - 1] + 1 == str[i + 1]) {
printf ("%c", str[i + 1]); i++;
}
else {
int n = str[i - 1] + 1;
int m = p2;
while (n < str[i + 1]) {
for (int j = 1; j <= m; j++) printf ("%c", n - 32);
n++;
}
}
}
else if (p3 == 2) {
if (judge (str[i - 1], str[i + 1])) {
cout << "-" << str[i + 1]; i++; //cout << "1" << endl; //没有执行????
}
else if (str[i - 1] >= str[i + 1]) {
printf ("-%c", str[i + 1]); i++;
}
else if (str[i - 1] + 1 == str[i + 1]) {
printf ("%c", str[i + 1]); i++;
}
else {
int n = str[i + 1] - 1;
int m = p2;
while (n > str[i - 1]) {
for (int j = 1; j <= m; j++) {
if (n >= '0' && n <= '9') printf ("%c", n);
else printf ("%c", n - 32);
}
//cout << "1" << endl;
n--;
}
}
}
i ++;
}
else {
cout << str[i];
i ++;
}
}
}
if (p1 == 3) {
int i = 0;
while (str[i] != '\0') {
if (str[i] == '-') {
if (p3 == 1) {
if (judge (str[i - 1], str[i + 1])) {
cout << "-" << str[i + 1]; i++;
}
else if (str[i - 1] >= str[i + 1]) {
printf ("-%c", str[i + 1]); i++;
}
else if (str[i - 1] + 1 == str[i + 1]) {
printf ("%c", str[i + 1]); i++;
}
else {
int n = str[i - 1] + 1;
int m = p2;
while (n < str[i + 1]) {
for (int j = 1; j <= m; j++) printf ("*");
n++;
}
}
}
else if (p3 == 2) {
if (judge (str[i - 1], str[i + 1])) {
cout << "-" << str[i + 1]; i++;
}
if (str[i - 1] >= str[i + 1]) {
printf ("-%c", str[i + 1]); i ++;
}
else if (str[i - 1] + 1 == str[i + 1]) {
printf ("%c", str[i + 1]); i ++;
}
else {
int n = str[i + 1] - 1;
int m = p2;
while (n > str[i - 1]) {
for (int j = 1; j <= m; j++) printf ("*");
n--;
}
}
}
i ++;
}
else {
cout << str[i];
i ++;
}
}
}
cout << endl;
}
int main() {
cin >> p1 >> p2 >> p3;
cin >> str;
solve();
return 0;
}