zoukankan      html  css  js  c++  java
  • c#編寫聖誕樹算法﹐及相關問題。

    using System;
    namespace sendantree
    {
     /// <summary>
     /// Class1 的摘要描述。
     /// </summary>
     public class Class1
     {
         private static string linePara=""; 

      //算法依據
      //H=3, L=H/2=3/2=1, W=H*2-1=3*2-1=5
      //H=5, L=H/2=5/2=2, W=H*2-1=5*2-1=9 
      [STAThread]
      static void Main(string[] args)
      {   
       string Input1=Console.ReadLine();
       int Input=Convert.ToInt32(Input1);
       int i=0;
       if(Input==0)return;

       int yezi =Input*2-1; //樹枝的葉子數。
       int lineCount=yezi-(Input/2); //樹的高度。

       while (i<lineCount)
       {  
        linePara="";    
        if(i< yezi/2+1)
        {               
         for(int n =0;n < yezi/2-i;n++)
         { 
          linePara=linePara +"-";
         }  
         for (int x=0;x<yezi-( (yezi/2-i)*2 );x++)
         {
          linePara=linePara +"*";
         }
         for(int n =0;n < yezi/2-i;n++)
         { 
          linePara=linePara +"-";
         } 
        }
        else
        {
         for(int n =0;n < yezi/2;n++)
         { 
          linePara=linePara +"-";
         }  
         linePara=linePara +"*"; 
         for(int n =0;n < yezi/2;n++)
         { 
          linePara=linePara +"-";
         } 
        }
        Console.Write(linePara+"\n");
                    i++;                            
       }  
       Console.Read(); //暫停
      }  
     }
    }

  • 相关阅读:
    Kubernetes 服务入口管理 Traefik Ingress Controller
    flex的titlewindow如何自适应浏览器的宽度和高度
    JQuery的事件中使用this
    jQuery控制 input 不可编辑
    jquery 操作 input显示或者隐藏
    Word 创建模板
    HTML转PDF
    SQL server 自增主键重新从1开始
    读取 .properties文件到数据库
    根据json生成java实体类文件
  • 原文地址:https://www.cnblogs.com/jun1111/p/AB1002.html
Copyright © 2011-2022 走看看