2017年9月8日京东“地图数据融合”大题1
给定字符串s,请计算输出含有连续两个s作为字串的最短字符串。注意两个s可能有重叠部分。例如:输入:abracadabra输出:abracadabracadabra using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace JD1 { class Program { static void Main(string[] args) { string str1; while (true) { str1 = Console.ReadLine(); if(str1.Length>=1&&str1.Length<=50) { if (System.Text.RegularExpressions.Regex.IsMatch(str1, "[A-Z]")) { str1 = str1.ToLower(); break; } break; } else { Console.WriteLine("请输入长度在1和50之间的字符串!"); } } string frontStr = ""; string endStr = ""; for (int i = 1; i < str1.Length;i++ ) { string tempStr1 = str1.Substring(0,i); string tempStr2 = str1.Substring(i); if (tempStr1.Length > tempStr2.Length) { if(tempStr1.Contains(tempStr2)) { string tempChar1 = tempStr1.Substring(0,tempStr2.Length); string tempChar2 = tempStr2; if (tempChar1.Equals(tempChar2)) { endStr=tempStr2; frontStr = tempStr1; break; } else continue; } } else { if(tempStr2.Contains(tempStr1)) { string tempChar1 = tempStr2.Substring(0, tempStr1.Length); string tempChar2 = tempStr1; if (tempChar1.Equals(tempChar2)) { endStr = tempStr1; frontStr = tempStr2; break; } else continue; } } } Console.WriteLine(frontStr+frontStr+endStr); } } }
#京东#