解题思路:
注意事项:
参考代码:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
int p1, p2, p3, i, j;
char str[101], c;
scanf("%d %d %d", &p1, &p2, &p3);
scanf("%s", str);
for (i = 0; i < strlen(str); i++) {
if (str[i] != '-') {
printf("%c", str[i]);
} else {
if (isalpha(str[i - 1]) && isalpha(str[i + 1]) && str[i - 1] < str[i + 1]) {
if (p3 == 1) {
if (p1 == 1) {
for (c = (char)(tolower(str[i - 1]) + 1); c < tolower(str[i + 1]); c++) {
for (j = 1; j <= p2; j++) {
printf("%c", c);
}
}
} else if (p1 == 2) {
for (c = (char)(toupper(str[i - 1]) + 1); c < toupper(str[i + 1]); c++) {
for (j = 1; j <= p2; j++) {
printf("%c", c);
}
}
} else if (p1 == 3) {
int times = (int)(tolower(str[i + 1]) - tolower(str[i - 1])) - 1;
for (j = 1; j <= p2 * times; j++) {
printf("*");
}
}
} else if (p3 == 2) {
if (p1 == 1) {
for (c = (char)(tolower(str[i + 1]) - 1); c > tolower(str[i - 1]); c--) {
for (j = 1; j <= p2; j++) {
printf("%c", c);
}
}
} else if (p1 == 2) {
for (c = (char)(toupper(str[i + 1]) - 1); c > toupper(str[i - 1]); c--) {
for (j = 1; j <= p2; j++) {
printf("%c", c);
}
}
} else if (p1 == 3) {
int times = (int)(toupper(str[i + 1]) - toupper(str[i - 1])) - 1;
for (j = 1; j <= p2 * times; j++) {
printf("*");
}
}
}
} else if (isdigit(str[i + 1]) && isdigit(str[i - 1]) && str[i + 1] > str[i - 1]) {
if (p1 == 3) {
int times = str[i + 1] - str[i - 1] - 1;
for (j = 1; j <= times * p2; j++) {
printf("*");
}
} else {
if (p3 == 1) {
for (c = str[i - 1] + 1; c < str[i + 1]; c++) {
for (j = 1; j <= p2; j++) {
printf("%c", c);
}
}
} else if (p3 == 2) {
for (c = str[i + 1] - 1; c > str[i - 1]; c--) {
for (j = 1; j <= p2; j++) {
printf("%c", c);
}
}
}
}
} else {
printf("-");
}
}
}
printf("\n");
return 0;
}
0.0分
0 人评分
C语言训练-排序问题<2> (C++代码)浏览:879 |
【亲和数】 (C语言代码)浏览:855 |
最长单词 (C语言代码)浏览:1362 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:1195 |
本人酷爱递归实现很多问题,这里也是浏览:547 |
WU-输出九九乘法表 (C++代码)浏览:1654 |
WU-链表数据求和操作 (C++代码)浏览:1312 |
WU-整除问题 (C++代码)浏览:610 |
1113题解浏览:784 |
有关字符,字符串的输入输出函数说明浏览:477 |