• [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;
    }
    

      

  • 相关阅读:
    HTML的初体验
    HTML兼容问题——HACK技术
    JavaScript 小试牛刀
    JavaScript 初识
    HTML5+CSS3 代码简写篇
    原生JavaScript技巧
    Java1变量数据类型和运算符
    java6循环结构二
    java3选择结构一
    java2变量数据类型和运算符
  • 原文地址:https://www.cnblogs.com/zhenghaotian/p/7091233.html
Copyright © 2020-2023  润新知