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(); //暫停
      }  
     }
    }

  • 相关阅读:
    squid代理
    日志、远程日志、日志轮询、DHCP
    环境变量、进程
    rpm、yum
    filesystem安装后产生所有目录
    vRO 添加已有磁盘到VM
    python笔记-8(线程,进程,协程,io多路复用)
    python笔记-7(面向对象、类、面向对象进阶、异常处理、断言、反射、网络(套接字)编程、)
    python3 封装
    python3 继承
  • 原文地址:https://www.cnblogs.com/jun1111/p/AB1002.html
Copyright © 2011-2022 走看看