zoukankan      html  css  js  c++  java
  • 面试题目记录

    面试题目1: 把一个段落中的日期格式字符串更改格式,由MM/DD/YYYY 更改为 DD/MM/YYYY

    比如 输入语句为  "Last time it rained was on 07/25/2013 and today is 08/09/2013"  转换后的输出语句为  "Last time it rained was on 25/07/2013 and today is 09/08/2013"

    方法: 采用正则表达式,把段落中的日期格式字符串替换

     static void Main(string[] args)
            {
    
                string newStr = UpdateDateFormat("Last time it rained was on 07/25/2013 and today is 08/09/2013");
                Console.WriteLine(newStr);
            }
    
    
    
            public static string UpdateDateFormat(string a)
            {
    
                string[] str1 = a.Split(' ');
    
                var pattern = @"(d+)/(d+)/(d+)";
    
                Regex rgx = new Regex(pattern, RegexOptions.None,TimeSpan.FromMilliseconds(150));
    
                foreach (var item in str1)
                {
    
                    var newItem = "";
    
                    if (item.IndexOf('/') > 0)
                    {
    
                        //a = a.Replace(item, Convert.ToDateTime(item).ToString("dd/MM/yyyy"));
                        newItem = Regex.Replace(item, pattern, "$2/$1/$3", RegexOptions.None, TimeSpan.FromMilliseconds(150));
    
                        a = a.Replace(item, newItem);
    
                    }
    
    
                }
    
                return a;
    
            }

     2. 判断一条语句是否是 palindrome (回文)

    public static bool IsPalindrome(string s)
    
            {
    
                
    
                string newS = s.Replace(" ", "").ToLower();
    
                //Get the first and last index of the string
    
                 int beginIndex = 0;
    
                int endIndex = newS.Length - 1;
    
    
    
    
                //Compare and judge whether the char is same from begin and end direction
    
                while (beginIndex < endIndex)
    
                {
    
                    if (newS[beginIndex] != newS[endIndex])
    
                        return false;
    
    
    
    
                    beginIndex++;
    
                    endIndex--;
    
                }
    
    
    
    
                return true;
    
            }
  • 相关阅读:
    verilog之计数器0~9999——数码管显示
    C语言的谜题
    modelsim SE6.2b的常用问题
    [转载]MDK常见报错(编译arm)
    Nios II之LED实验(SDRAM+EPCS4配置)————基于Altera的DE0开发板
    poj2210
    poj1161
    poj1555
    poj2337
    poj1107
  • 原文地址:https://www.cnblogs.com/wphl-27/p/5872065.html
Copyright © 2011-2022 走看看