zoukankan      html  css  js  c++  java
  • XX面试题

    是一题笔试题,也没有什么难点,当时写这道题的时候太唐突了,
    今天回来再机子上重新完善完善了

    题面:请打印以下图形

       *
      ***
     *****
    *******
     *****
      ***
       *
     
    class Program
        {
            
    private const string flag = "*";
            
    private const char snull = ' ';
            
    private const int length = 7;

            
    /// <summary>
            
    /// 主函数
            
    /// </summary>
            
    /// <param name="args"></param>
            static void Main(string[] args)
            {
                
    //----------正向打印
                for (int i = 0; i <= length; i++)
                    
    if (i % 2 != 0)
                        PrintFlag(i);

                
    //-----------反向打印
                for (int i = length - 2; i > 0; i--)
                    
    if (i % 2 != 0)
                        PrintFlag(i);

                Console.Read();
            }

            
    /// <summary>
            
    /// 打印标记
            
    /// </summary>
            
    /// <param name="currentIndex">当前索引</param>
            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);
            }

            
    /// <summary>
            
    /// 获取“标记”位置
            
    /// </summary>
            
    /// <param name="currentIndex">当前索引</param>
            
    /// <param name="flag">标记</param>
            
    /// <returns></returns>
            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;
            }
        }




    如果有更好的方法,希望大家多补充哈
  • 相关阅读:
    css笔记
    应用软件常用性能数据描述
    软件性能
    对换工作
    微软网络监视器
    神经衰落的治疗方法
    测试工具Loadrunner日志参数的设置与使用 http://epanchen.javaeye.com/blog/317594
    常见的性能测试方法
    web性能测试需要监控IIS的哪些性能指标 http://bbs.51testing.com/thread13221111.html
    应用软件性能数据分类
  • 原文地址:https://www.cnblogs.com/wfcfan/p/1579758.html
Copyright © 2011-2022 走看看