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;
    
            }
  • 相关阅读:
    寻找——无限游戏破关(一)
    运维入职梳理文档
    seafile 旧版本升级新版本时python库引用报错
    操作系统-计算进程的物理地址(例题)
    拉取微信公众号视频文件
    洛谷-P3654 First Step (ファーストステップ)
    洛谷-P3392 涂国旗
    洛谷-P1706 全排列问题
    洛谷-P1157 组合的输出
    洛谷-P2241 统计方形(数据加强版)
  • 原文地址:https://www.cnblogs.com/wphl-27/p/5872065.html
Copyright © 2011-2022 走看看