记录编号 442529 评测结果 AAAAAAAAAA
题目名称 [NOIP 2007]字符串的展开 最终得分 100
用户昵称 GravatarHeHe 是否通过 通过
代码语言 C++ 运行时间 0.002 s
提交时间 2017-08-27 18:36:43 内存使用 0.56 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

inline char getc(void) { 
    static char buf[1 << 18], *fs, *ft;
    return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}

inline int read(void) { 
    register int res = 0;
    register char tmp = getc();
    while(!isdigit(tmp)) tmp = getc();
    while(isdigit(tmp))
        res = ((res + (res << 2)) << 1) + (tmp ^ 0x30),
        tmp = getc();
    return res;
}

inline int read(char *s) { 
    register char *p = s, tmp = getc();
    while(!isgraph(tmp)) tmp = getc();
    while(isgraph(tmp))
        *(p++) = tmp, tmp = getc();
    return p - s;
}

#define MAXN (110)

inline bool check(char a, char b);

char s[MAXN], p1, p2, p3;
int len;

int main() { 
#ifndef LOCAL
    freopen("expand.in", "r", stdin);
    freopen("expand.out", "w", stdout);
#endif
    p1 = read(), p2 = read(), p3 = read();
    len = read(s);
    if(p1 == 2) 
        for(int i = 0; i < len; ++i) 
            if(s[i] == '-') 
                if(i == 0 || s[i - 1] >= s[i + 1] || !check(s[i - 1], s[i + 1])) putchar('-');
                else if(p3 == 1) 
                    if(isdigit(s[i - 1]))
                        for(char c = s[i - 1] + 1; c < s[i + 1]; ++c) 
                            for(char p = 0; p < p2; ++p) putchar(c);
                    else if(s[i - 1] <= 'Z') 
                        for(char c = s[i - 1] + 1; c < s[i + 1]; ++c)
                            for(char p = 0; p < p2; ++p) putchar(c);
                    else for(char c = s[i - 1] - 31, k = s[i + 1] - 32; c < k; ++c)
                        for(char p = 0; p < p2; ++p) putchar(c);
                else if(isdigit(s[i - 1]))
                    for(char c = s[i + 1] - 1; c > s[i - 1]; --c) 
                        for(char p = 0; p < p2; ++p) putchar(c);
                else if(s[i - 1] <= 'Z') 
                    for(char c = s[i + 1] - 1; c > s[i - 1]; --c)
                        for(char p = 0; p < p2; ++p) putchar(c);
                else for(char c = s[i + 1] - 33, k = s[i - 1] - 32; c > k; --c)
                    for(char p = 0; p < p2; ++p) putchar(c);
            else putchar(s[i]);
    else if(p1 == 1) 
        for(int i = 0; i < len; ++i) 
            if(s[i] == '-') 
                if(i == 0 || s[i - 1] >= s[i + 1] || !check(s[i - 1], s[i + 1])) putchar('-');
                else if(p3 == 1) 
                    if(isdigit(s[i - 1]))
                        for(char c = s[i - 1] + 1; c < s[i + 1]; ++c) 
                            for(char p = 0; p < p2; ++p) putchar(c);
                    else if(s[i - 1] >= 'a') 
                        for(char c = s[i - 1] + 1; c < s[i + 1]; ++c)
                            for(char p = 0; p < p2; ++p) putchar(c);
                    else for(char c = s[i - 1] + 33, k = s[i + 1] + 32; c < k; ++c)
                        for(char p = 0; p < p2; ++p) putchar(c);
                else if(isdigit(s[i - 1]))
                    for(char c = s[i + 1] - 1; c > s[i - 1]; --c) 
                        for(char p = 0; p < p2; ++p) putchar(c);
                else if(s[i - 1] >= 'a') 
                    for(char c = s[i + 1] - 1; c > s[i - 1]; --c)
                        for(char p = 0; p < p2; ++p) putchar(c);
                else for(char c = s[i + 1] + 31, k = s[i - 1] + 32; c > k; --c)
                    for(char p = 0; p < p2; ++p) putchar(c);
            else putchar(s[i]);
    else for(int i = 0; i < len; ++i) 
        if(s[i] == '-') 
            if(i == 0 || s[i - 1] >= s[i + 1] || !check(s[i - 1], s[i + 1])) putchar('-');
            else for(int j = 0, p = (int)p2 * (s[i + 1] - s[i - 1] - 1); j < p; ++j) putchar('*');
        else putchar(s[i]);
    return 0;
}

inline bool check(char a, char b) { 
    if(isdigit(a)) return isdigit(b);
    else if(isalpha(a)) return isalpha(b);
    return false;
}