</pre><p style="margin: 0px; padding: 0px; font-weight: bold; line-height: 56px;"><pre code_snippet_id="1761415" snippet_file_name="blog_20160714_1_8881116" name="code" class="html"><span style="font-size: 16px; font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">来源</span>
NOIP2007复赛 提高组 第二题
#include<stdio.h>
#include<stdlib.h>
char A[100];
int P = 0;
void hanshu(char *a, int p1, int p2, int p3)
{
int i = 0;
char x, y;
while (a[i])
{
if (a[i] == '-')
{
x = a[i - 1];
y = a[i + 1];
if ((y - x) == 1)//相邻
{
A[P++] = '\0';
}
else if ((y - x) <= 0)//小
{
A[P++] = '-';
A[P++] = '\0';
}
else { //大
if (p1 == 3) //填充星星
{
for (int i = 1; i <= (p2*(y - x - 1)); i++)
{
A[P++] = '*';
}
A[P++] = '\0';
}
else
{
if (x <= '9'&&y <= '9'&&x >= '0'&&y >= '0')//数字
{
if (p3 == 1) //顺序输出
{
for (int i = 1; i <= (y - x - 1); i++)
{
for (int j = 1; j <= p2; j++)
{
A[P++] = x + i;
}
}
A[P++] = '\0';
}
if (p3 == 2) //逆序输出
{
for (int i = 1; i <= (y - x - 1); i++)
{
for (int j = 1; j <= p2; j++)
{
A[P++] = y - i;
}
}
A[P++] = '\0';
}
}
else //字母
{
if (p1 == 1 && p3 == 1) //小写 顺序输出
{
for (int i = 1; i <= (y - x - 1); i++)
{
for (int j = 1; j <= p2; j++)
{
if (x < 'a') //本身是大写
{
A[P++] = x + i + 32;
}
else //本身小写
{
A[P++] = x + i;
}
}
}
A[P++] = '\0';
}
if (p1 == 2 && p3 == 1) //大写 顺序输出
{
for (int i = 1; i <= (y - x - 1); i++)
{
for (int j = 1; j <= p2; j++)
{
if (x < 'a') //本身是大写
{
A[P++] = x + i;
}
else //本身小写
{
A[P++] = x + i - 32;
}
}
}
A[P++] = '\0';
}
if (p1 == 1 && p3 == 2) //小写 逆序输出
{
for (int i = 1; i <= (y - x - 1); i++)
{
for (int j = 1; j <= p2; j++)
{
if (x < 'a') //本身大写
{
A[P++] = y - i + 32;
}
else //本身小写
{
A[P++] = y - i;
}
}
}
A[P++] = '\0';
}
if (p1 == 2 && p3 == 2) //大写 逆序输出
{
for (int i = 1; i <= (y - x - 1); i++)
{
for (int j = 1; j <= p2; j++)
{
if (x < 'a') //本身大写
{
A[P++] = y - i;
}
else //本身小写
{
A[P++] = y - i - 32;
}
}
}
A[P++] = '\0';
}
}
}
}
}
i++;
}
}
void main()
{
int p1 = 0, p2 = 0, p3 = 0;
char a[100];
for (int i = 0; i < 100; i++)
A[i] = 0;
scanf("%d%d%d", &p1, &p2, &p3);
scanf("%s", &a);
hanshu(a, p1, p2, p3);
int i = 0;
P = 0;
while (a[i])
{
if (a[i] == '-')
{
while (A[P])
{
printf("%c", A[P]);
P++;
}
P++;
}
else
{
printf("%c", a[i]);
}
i++;
}
}