• 折纸问题java实现


     1 /**
     2      * 折纸问题 这段代码写的太low了 本人水平有限 哎。。。 全是字符串了
     3      * @param n
     4      * @return
     5      * @date 2016-10-7
     6      * @author shaobn
     7      */
     8     public static String[] flodpaper(int n){
     9         int length = (int)Math.pow(2,n)-1;
    10         int position = (int)Math.pow(2,n-1)-1;
    11         String[] strings = new String[length];
    12         strings[position] = "down";
    13         if(n==1){
    14             return strings;
    15         }else {
    16             String string_2 = new String();
    17             for(String string:flodpaper(n-1)){
    18                 string_2+=string;
    19                 string_2+=" ";
    20             }
    21             string_2+="down";
    22             string_2+=" ";
    23             String string_3 = new String();
    24             for(String string:flodpaper(n-1)){
    25                 if(string.equals("down")){
    26                     string_3+="up";
    27                     string_3+=" ";
    28                 }else {
    29                     string_3+="down";
    30                     string_3+=" ";
    31                 }
    32             }
    33             String[] strings4 = string_3.split(" ");
    34             for(int i = strings4.length-1;i>=0;i--){
    35                 string_2+=strings4[i];
    36                 string_2+=" ";
    37             }
    38             String[] strings2 = string_2.split(" ");
    39             return strings2;
    40         }
    41     }

    请把纸条竖着放在桌⼦上,然后从纸条的下边向上⽅对折,压出折痕后再展 开。此时有1条折痕,突起的⽅向指向纸条的背⾯,这条折痕叫做“下”折痕 ;突起的⽅向指向纸条正⾯的折痕叫做“上”折痕。如果每次都从下边向上⽅ 对折,对折N次。请从上到下计算出所有折痕的⽅向。

    给定折的次数n,请返回从上到下的折痕的数组,若为下折痕则对应元素为"down",若为上折痕则为"up"
  • 相关阅读:
    求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。
    getchar函数
    计算机网络04-ip与子网划分
    计算机网络03-传输层、可靠数据传输、UDP与TCP
    计算机网络02-应用层(http、email、dns)
    游戏-图形学学习路线
    markDown 入门
    webpack 入门级 傻瓜式教学
    npm 切换 cnpm 切换淘宝镜像源
    vue 父组件在接收子组件的同时传递一个当前的数据
  • 原文地址:https://www.cnblogs.com/assassin666/p/5936253.html
Copyright © 2020-2023  润新知