字符串的展开

题目大意:

根据题目规则展开字符串。

正文:

模拟题,有些细节不能大意。

代码:


int main()
{
	scanf("%d%d%d", &p1, &p2, &p3);
	scanf("%s", str);
	for (int i = 0; i < strlen(str); i++)
	{
		if(str[i] != '-') 
		{
			ans[ansl++] = str[i];
			continue;
		}
		if(str[i - 1] == str[i + 1] - 1) continue;
		if(((str[i - 1] >= '0' && str[i - 1] <= '9') && str[i + 1] > '9') || (i == 0 || i == strlen(str) - 1) || (str[i - 1] == '-' || str[i + 1] == '-'))
		{
			ans[ansl++] = '-';
			continue;
		}
		if(str[i - 1] < str[i + 1])
		{
			for (char c = (p3==1?(str[i - 1] + 1):(str[i + 1] - 1)); (p3==1?(c < str[i + 1]):(c > str[i - 1])); (p3==1?c++:c--))
			{
				for (int j = 1; j <= p2; j++)
				{
					if(p1 == 1)
					{
						if(c >= 'A' && c <= 'Z') ans[ansl++] = c - ('A' - 'a');
						else ans[ansl++] = c;
					}else
						if(p1 == 2)
						{
							if(c >= 'a' && c <= 'z') ans[ansl++] = c + ('A' - 'a');
							else ans[ansl++] = c;
						}else
							if(p1 == 3)
								ans[ansl++] = '*';
				}
			}
		}else
		{
			ans[ansl++] = '-';
		}
	}
	for (int i = 0; i < ansl; i++) printf("%c", ans[i]);
	return 0;
}

posted @ 2020-08-10 17:33  Jayun  阅读(220)  评论(0编辑  收藏  举报