腾讯移动端开发笔试编程题

第一题:和谐的数字 100%
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApp1 {  class Program  {  static void Main(string[] args)  {  string s;  s = Console.ReadLine();  int n = Convert.ToInt32(s);  while (n-- > 0)  {  s = Console.ReadLine();  int i = Convert.ToInt32(s);  Console.WriteLine(Judge(i) ? "Yes" : "No");  }  Console.ReadKey();  }  private static bool Judge(int i)  {  int n = i;  int sum = 0;  while(i != 0)  {  sum += i % 10;  i /= 10;  }  return (n % sum == 0);  }  } }
第二题:巧克力球 100%
using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; namespace ConsoleApp1 {  class Program  {  static void Main(string[] args)  {  string s;  s = Console.ReadLine();  int n = Convert.ToInt32(s);  //就是求连续0个数的乘积,首先要保证头尾都是1  //先去空格  s = Console.ReadLine();  s = s.Replace(" ", "");  //去掉头尾的0  s = s.Trim('0');    int sum = 1;  //最多s.Length - 2个0  int max = s.Length - 2;  for(int i = 1; i < max; i++)  {  Regex regex = new Regex("(?=[1][0]{" + i + "}[1])");  int t = regex.Matches(s).Count;  sum *= (int)Math.Pow(i + 1, t);  }  Console.WriteLine(sum);  Console.ReadKey();  }  } }
第三题:能量矿石 20% 求大佬解答
using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; namespace ConsoleApp1 {  class Program  {  static void Main(string[] args)  {  string s;  s = Console.ReadLine();  string p;  p = Console.ReadLine();  List<string> collection = ps(p);  string pattern = "(?:(" + collection[0];  for(int i = 1; i < collection.Count; i++)  {  pattern += "|" + collection[i];  }  pattern += ")+)";  //Console.WriteLine(pattern);  Regex regex = new Regex(pattern);  MatchCollection matchCollection = regex.Matches(s);  int max = 0;  foreach (Match match in matchCollection)  {  int len = match.ToString().Length;  if (len > max)  {  max = len;  }  }  Console.WriteLine(max * max);  Console.ReadKey();  }  //去除回文和重复  private static List<string> ps(string p)  {  List<string> all = new List<string>();  int len = p.Length;  while (len > 0)  {  int movement = p.Length - len + 1;  if (p.Substring(len - 1).Equals(p.Substring(0, movement)))  all.Add(p + p.Substring(movement));  len--;  }  return all;  }  } }

#腾讯#
全部评论
前端和你的题目是一样的,这个是前端的 https://blog.csdn.net/u013594470/article/details/82726151
点赞 回复 分享
发布于 2018-09-16 17:54
第三道的思路我说先找出有子序列的头坐标的集合,然后再去计算长度
点赞 回复 分享
发布于 2018-09-16 17:56

相关推荐

点赞 评论 收藏
分享
找不到工作死了算了:没事的,雨英,hr肯主动告知结果已经超越大部分hr了
点赞 评论 收藏
分享
点赞 4 评论
分享
牛客网
牛客企业服务