记录编号 10968 评测结果 AAAAAAAAAA
题目名称 [NOIP 2007]字符串的展开 最终得分 100
用户昵称 Gravatar苏轼 是否通过 通过
代码语言 C++ 运行时间 0.004 s
提交时间 2009-07-08 16:56:02 内存使用 0.25 MiB
显示代码纯文本
#include <stdio.h>
#include <ctype.h>

int p1, p2, p3;
FILE *fin;
FILE *fout;


void Expand (char str, /*int *len,*/ char ch);
int Transp (int ch);

int main (void)
{
    fin=fopen("expand.in", "r");
    fout=fopen("expand.out", "w");

//    int len=-1;
    char c, bak;
//    char ans[10000]={'\0'};

    fscanf(fin, "%d%d%d", &p1, &p2, &p3);

    fgetc(fin);

//    ans[++len]=fgetc(fin);
    fputc(bak=fgetc(fin), fout);
    while ((c=fgetc(fin))!='\n' && c!=EOF)
    {
        if (c=='-')
        {
            char tmp;

            tmp=fgetc(fin);

            if (tmp>bak &&
               ( (isdigit(tmp) && isdigit(bak)) ||
                 (isalpha(tmp) && isalpha(bak)) ) )
            {
                Expand(bak, /*&len,*/ tmp);
                //ans[++len]=tmp;
                fputc(tmp, fout);

            }
            else
            {
                //ans[++len]=c;
                fputc(c, fout);
                //ans[++len]=tmp;
                fputc(tmp, fout);
            }

            bak=tmp;
        }
        else
        {
            //ans[++len]=c;
            fputc(c, fout);
            bak=c;
        }
    }

//    fprintf(fout, "%s\n", ans);

    fclose(fin);
    fclose(fout);

    return 0;
}

void Expand(char str, /*int *len ,*/char ch)
{
    int i, j/*, olen*/;

//    olen=*len;
    if (p3==1)
        for (i=str+1; i<ch; i++)
            for (j=1; j<=p2; j++)
                fputc(Transp(i), fout);
    else
        for (i=ch-1; i>str; i--)
            for (j=1; j<=p2; j++)
                fputc(Transp(i), fout);

}

int Transp (int ch)
{
    if (p1==2 && isalpha(ch))
        return toupper(ch);
    else if (p1==3)
        return '*';

    return ch;
}