zoukankan      html  css  js  c++  java
  • 某公司的一个题面试题(wfcfan)

    是一题笔试题,也没有什么难点,当时写这道题的时候太唐突了,

    今天回来再机子上重新完善完善了
    题面:请打印以下图形

       *
      ***
     *****
    *******
     *****
      ***
       *
    code:
    class Program
        {
            private const string flag = "*";
            private const char snull = ' ';
            private const int length = 7;
    
            static void Main(string[] args)
            {
                for (int i = 0; i <= length; i++)
                {
                    if (i % 2 != 0)
                        PrintFlag(i);
    
                    if (i == length)
                    {
                        for (int j = length - 2; j > 0; j--)
                            if (j % 2 != 0)
                                PrintFlag(j);
                    }
                }
                Console.Read();
            }
    
            static void PrintFlag(int currentIndex)
            {
                string t = string.Empty, s = string.Empty;
                for (int i = 0; i < currentIndex; i++)
                {
                    t += flag;
                }
                s = GetLocation(currentIndex, t);
                Console.WriteLine(s);
            }
    
            static string GetLocation(int currentIndex,string flag)
            {
                int totalcount = length;
                if (currentIndex == totalcount)
                    return flag;
    
                int startlocation = (totalcount - currentIndex) / 2;
                string temp = flag.PadLeft(startlocation + currentIndex, snull);
                temp = temp.PadRight(totalcount, snull);
                return temp;
            }
    }
    
    code2
    class Program{
       static void Main(string[] args)
      {       Console.WriteLine("   *   ");
              Console.WriteLine("  ***  ");
              Console.WriteLine(" ***** ");
          Console.WriteLine("*******");
      Console.WriteLine(" ***** ");
      Console.WriteLine("  ***  ");
       Console.WriteLine("   *   ");
       Console.Read();
     }
    }
    code3
    Console.WriteLine(@"   *
    
      ***
    
     *****
    
    *******
    
     *****
    
      ***
    
       *");
    
    
    code4
    class Program
    {
    static void Main(string[] args)
    {
    PrintStar(9);
    }
    public static void PrintStar(int maxNumber)
    {
    
    //可以在此检验maxNumber是否为奇数
    
    
    ///正打
    for (int i = 1; i <= maxNumber;)
    {
    ShowConsoleStar(i,maxNumber);
    i = i + 2;
    }
    //反打
    for (int i = maxNumber - 2; i >= 1; )
    {
    ShowConsoleStar(i,maxNumber );
    i = i - 2;
    }
    }
    private static void ShowConsoleStar(int starNumber,int maxNumber)
    {
    //补位
    for (int i = 1; i <= (maxNumber - starNumber)/2;i++ )
    {
    Console.Write(" "); 
    }
    //打星
    for (int i = 1; i <=starNumber; i++)
    {
    Console.Write("*"); 
    }
    //换行
    Console.WriteLine(); 
    
    }
    
    }
    
    http://www.cnblogs.com/wfcfan/archive/2009/10/09/1579758.html
  • 相关阅读:
    情报收集:Metasploit命令、查询网站和测试网站
    Hbase 学习笔记5----hbase region, store, storefile和列簇的关系
    Hbase 学习笔记4----原理
    Hbase 学习笔记3----操作以及维护
    Hbase 学习笔记2----概念
    Hbase 学习笔记1----shell
    Flume日志收集 总结
    Hadoop应用开发实战案例 第2周 Web日志分析项目 张丹
    2016.4.9-关于“放生”反而促进“捕猎”的思考
    Hadoop应用开发实战案例 第1周 基本介绍
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/1741876.html
Copyright © 2011-2022 走看看