Chinaunix首页 | 论坛 | 博客
  • 博客访问: 166902
  • 博文数量: 33
  • 博客积分: 2143
  • 博客等级: 大尉
  • 技术积分: 807
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-31 10:24
个人简介

Show me the money

文章分类

全部博文(33)

文章存档

2015年(1)

2013年(1)

2011年(12)

2010年(14)

2009年(2)

2008年(2)

2005年(1)

我的朋友

分类: C/C++

2011-09-08 15:30:09

1.         继续简化

const char *coding1 = "@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# ){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c ;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')# }'+}##(!!/";

const char *coding2 = "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry";

int echo1(int p, const char *str)

{

    int i;

    for(i=0; ;i++)

        if(str[i] == p)

            return putchar(str[31 + i]);

}

int echo2(const char *str)

{

    while(*str != '/') {

        echo1(*str, coding2);

        str++;

    }

    return 1;

}

int echo(int t, int p, const char *str)

{

    int result, n;

    if( t > 1 )  {

        if(t < 3 ) {

            echo2(coding1);

            echo(1-p, -80, coding1 );

            result = echo(-13, -80, coding1 ) ;

        } else

            result = 1;

        if(t < p )

            echo( t+1, p , str) ;

        if( echo(-27+t, -80, coding1) && t == 2 )

            if (p < 13)

                echo (2, p +1, "%s %d %d\n");

        return result;

    } else if(t < 0) {

        if(t < -50) {

            result = echo1(p, str);

        } else { /* -50 <= t < 0 */

            int i;

            const char *x;

            for(i = t, x = str; i < 0 ; i++)

                while( *x++ != '/' ) {}

            result = echo2(x) ;

        }

    } else if( t == 1 )

        result = echo (2, 2 , "%s") ;

    else { /* t == 0 */

        result = echo2(str);

    }

    return result;

}

int main()

{

    return echo(1, 1, "");

}

 

2.         考虑到(基于初始条件对代码作出的假设)

1)        echo函数不会返回零

2)        1-p < -50永不成立

3)        -27 + t < -50永不成立

4)        t < 0 永不成立

5)        t = 0永不成立

继续简化代码

const char *coding1 = "@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# ){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c ;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')# }'+}##(!!/";

const char *coding2 = "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry";

int echo1(int p, const char *str)

{

    int i;

    for(i=0; ;i++)

       if(str[i] == p)

           return putchar(str[31 + i]);

}

int echo2(const char *str)

{

    while(*str != '/') {

       echo1(*str, coding2);

       str++;

    }

    return 1;

}

int echo3(int t, const char *str)

{

    int i;

    for(i = t; i < 0 ; i++)

       while( *str++ != '/' ) {}

    return echo2(str) ;

}

int echo(int t, int p, const char *str)

{

    int result, n;

    if( t > 1 )  {

       if(t < 3) {

           echo2(coding1);

           echo3(1 - p, coding1);

           result = echo3(-13, coding1) ;

       } else

           result = 1;

       if(t < p)

           echo(t+1, p, str);

       echo3(-27 + t, coding1 );

       if( t == 2 && p < 13)

           echo (2, p +1, "%s %d %d\n");

       return result;

    }

    return result;

}

int main()

{

    return echo (2, 2 , "%s") ;

}

 

3.         考虑到

1)        echo函数的返回值再无用处

2)        从初始条件开始,t > 1永远成立

继续简化

const char *coding1 = "@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# ){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c ;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')# }'+}##(!!/";

const char *coding2 = "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry";

int echo1(int p, const char *str)

{

    int i;

    for(i=0; ;i++)

        if(str[i] == p)

            return putchar(str[31 + i]);

}

int echo2(const char *str)

{

    while(*str != '/') {

        echo1(*str, coding2);

        str++;

    }

    return 1;

}

int echo3(int t, const char *str)

{

    int i;

    for(i = t; i < 0 ; i++)

        while( *str++ != '/' ) {}

    return echo2(str) ;

}

int echo(int t, int p, const char *str)

{

    if(t < 3) {

        echo2(coding1);

        echo3(1 - p, coding1);

        echo3(-13, coding1) ;

    }

    if(t < p)

        echo(t+1, p, str);

    echo3(-27 + t, coding1 );

    if( t == 2 && p < 13)

        echo (2, p +1, "%s %d %d\n");

    return 0;

}

int main()

{

    return echo (2, 2 , "%s") ;

}

 

16.  继续,t, p会形成一个循环,依次为

(2, 2)

(2, 3)

(3, 3)

(3, 4)

(4, 4)

(13,13)

消除递归调用,得到

const char *coding1 = "@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# ){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c ;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')# }'+}##(!!/";

const char *coding2 = "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry";

int echo1(int p, const char *str)

{

    int i;

    for(i=0; ;i++)

        if(str[i] == p)

            return putchar(str[31 + i]);

}

int echo2(const char *str)

{

    while(*str != '/') {

        echo1(*str, coding2);

        str++;

    }

    return 1;

}

int echo3(int t, const char *str)

{

    int i;

    for(i = t; i < 0 ; i++)

        while( *str++ != '/' ) {}

    return echo2(str) ;

}

int echo(int T, int P)

{

    int t, p;

    for(p = 2; p <= 13; p++) {

        echo2(coding1);

        echo3(1 - p, coding1);

        echo3(-13, coding1) ;

        for(t = p; t >= 2 ; t--)

            echo3(-27 + t, coding1 );

    }

    return 0;

}

int main()

{

    return echo (2, 2) ;

}

 

阅读(2158) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~