首页 > 代码库 > [luoguP1098] 字符串的展开(模拟)

[luoguP1098] 字符串的展开(模拟)

传送门

 

一个模拟。

 

代码

#include <cstdio>#include <cstring>#include <iostream>#define isword(x) ((x) >= ‘a‘ && (x) <= ‘z‘)#define swap(x, y) ((x) ^= (y) ^= (x) ^= (y))int n, p1, p2, p3, add, d, start, end;char s[1000001];int main(){	int i, j, k;	scanf("%d %d %d", &p1, &p2, &p3);	scanf("%s", s + 1);	n = strlen(s + 1);	for(i = 1; i <= n; i++)	{		if(s[i] != ‘-‘ || i == 1 || i == n || (isword(s[i - 1]) && isdigit(s[i + 1])) || (isdigit(s[i - 1]) && isword(s[i + 1])) || (s[i] == ‘-‘ && (s[i - 1] == ‘-‘ || s[i + 1] == ‘-‘))) putchar(s[i]);		else		{			if(s[i - 1] + 1 == s[i + 1]) continue;			if(s[i - 1] >= s[i + 1])			{				putchar(‘-‘);				continue;			}			add = 0;			d = 1;			start = s[i - 1] + 1;			end = s[i + 1];			if(p3 == 2) swap(start, end), start -= 1, end -= 1, d = -1;			if(p1 == 3)			{				for(j = 1; j <= p2; j++)					for(k = start; k != end; k += d) putchar(‘*‘);				continue;			}			if(isword(s[i - 1]) && p1 == 2) add -= 32;			for(k = start; k != end; k += d)				for(j = 1; j <= p2; j++)					putchar(k + add);		}	}	return 0;}

  

[luoguP1098] 字符串的展开(模拟)