当前位置: 首页 > wzjs >正文

网站免费建济南搜索引擎优化网站

网站免费建,济南搜索引擎优化网站,网站开发外包公司合同,软件开发app开发定制外包99用C#实现搜索字符串中用’(‘和’)‘包裹的最外层的里面里面的字符串&#xff0c;将里面的记录按一个或多个空格、换行或tab&#xff0c;或者是它的在一起的组合作为分隔&#xff0c;分隔出多个字符串组&#xff0c;如果组中有字符串中同时包含’<‘和’>’&#xff0c;则…

用C#实现搜索字符串中用’(‘和’)‘包裹的最外层的里面里面的字符串,将里面的记录按一个或多个空格、换行或tab,或者是它的在一起的组合作为分隔,分隔出多个字符串组,如果组中有字符串中同时包含’<‘和’>’,则在原始的字符串中该字符串的位置的前后插入字符`,最后返回修改过后的字符串,优化这个字符串处理算法,并给出所有的测试用例。

以下是C#代码,包括优化后的算法和测试用例:

using System;
using System.Collections.Generic;
using System.Text;public class StringProcessor
{public string ProcessString(string input){var outerPairs = FindOuterParenthesesPairs(input);List<int> insertPositions = new List<int>();foreach (var (start, end) in outerPairs){if (start > end)continue;string substr = input.Substring(start, end - start + 1);var groups = SplitIntoGroups(substr);foreach (var group in groups){int groupStartInSubstr = group.Start;int groupEndInSubstr = group.End;bool hasLT = false;bool hasGT = false;for (int i = groupStartInSubstr; i <= groupEndInSubstr; i++){char c = substr[i];if (c == '<') hasLT = true;else if (c == '>') hasGT = true;if (hasLT && hasGT) break;}if (hasLT && hasGT){int originalStart = start + groupStartInSubstr;int originalEnd = start + groupEndInSubstr;insertPositions.Add(originalStart);insertPositions.Add(originalEnd + 1);}}}insertPositions.Sort((a, b) => b.CompareTo(a));StringBuilder sb = new StringBuilder(input);foreach (int pos in insertPositions){sb.Insert(pos, '`');}return sb.ToString();}private List<(int Start, int End)> FindOuterParenthesesPairs(string input){List<(int, int)> pairs = new List<(int, int)>();int depth = 0;int currentStart = -1;for (int i = 0; i < input.Length; i++){char c = input[i];if (c == '('){depth++;if (depth == 1){currentStart = i + 1;}}else if (c == ')'){depth--;if (depth == 0 && currentStart != -1){int currentEnd = i - 1;if (currentStart <= currentEnd){pairs.Add((currentStart, currentEnd));}currentStart = -1;}}}return pairs;}private List<(int Start, int End)> SplitIntoGroups(string substr){List<(int, int)> groups = new List<(int, int)>();int currentGroupStart = -1;for (int i = 0; i < substr.Length; i++){if (IsWhitespace(substr[i])){if (currentGroupStart != -1){groups.Add((currentGroupStart, i - 1));currentGroupStart = -1;}}else{if (currentGroupStart == -1){currentGroupStart = i;}}}if (currentGroupStart != -1){groups.Add((currentGroupStart, substr.Length - 1));}return groups;}private bool IsWhitespace(char c){return c == ' ' || c == '\t' || c == '\n' || c == '\r';}
}public class Program
{public static void Main(){var processor = new StringProcessor();RunTestCases(processor);}private static void RunTestCases(StringProcessor processor){// 测试用例TestCase(processor, "", ""); // 空字符串TestCase(processor, "hello world", "hello world"); // 无括号TestCase(processor, "()", "()"); // 空括号TestCase(processor, "(a b c)", "(a b c)"); // 无<和>TestCase(processor, "(a <b> c)", "(a `<b>` c)"); // 单个<和>TestCase(processor, "(a <b) c)", "(a <b) c)"); // 不匹配的<和)TestCase(processor, "((a <b>))", "((a `<b>`))"); // 嵌套括号TestCase(processor, "(a\t<b>\n)", "(a\t`<b>`\n)"); // 混合空白符TestCase(processor, "( <a> <b> )", "( `<a>` `<b>` )"); // 多个组TestCase(processor, "start(middle<test> end)finish", "start(middle `<test>` end)finish"); // 混合内容TestCase(processor, "(a<b<c>>d)", "(a`<b<c>>`d)"); // 复杂嵌套<>}private static void TestCase(StringProcessor processor, string input, string expected){string result = processor.ProcessString(input);Console.WriteLine($"Input:    {input}");Console.WriteLine($"Expected: {expected}");Console.WriteLine($"Result:   {result}");Console.WriteLine($"Test {(result == expected ? "Passed" : "Failed")}\n");}
}

测试用例说明:

  1. 空字符串:输入为空,输出保持不变。
  2. 无括号:输入中没有括号,直接返回原字符串。
  3. 空括号:括号内无内容,不做处理。
  4. 无<和>的组:括号内的组不包含<和>,不插入反引号。
  5. 单个符合条件的组:组包含<和>,插入反引号。
  6. 不匹配的符号:组内只有<,不插入。
  7. 嵌套括号:仅处理最外层括号内的内容。
  8. 混合空白符:正确处理制表符和换行符。
  9. 多个组:每个符合条件的组独立处理。
  10. 混合内容:括号内外混合内容处理。
  11. 复杂嵌套符号:组内包含多个<和>符号。
http://www.dtcms.com/wzjs/324759.html

相关文章:

  • 做网站asp国内新闻最近新闻今天
  • 哪个网站容易做二级域名广州市口碑seo推广外包
  • 胶南网站建设多少钱谷歌商店下载官网
  • 兴力网站建设网络营销是什么专业
  • 做公司网站有用吗大型网站建站公司
  • 电子商务网站系统百度推广客户端怎样注册
  • 红色的网站seo在线培训课程
  • 开发一个小程序游戏要多少钱南宁网站seo优化公司
  • 网站手机端做app开发广州抖音seo
  • 浙江省工程建设信息网seo培训课程
  • 网站建设中山优化在线注册免费域名
  • 网站主机安全湖南网站seo找行者seo
  • 网站做淘宝客百度推广入口官网
  • 营销最好的方法seo网站优化收藏
  • 做网站的收益在哪app开发费用一般多少钱
  • 网站建设行业企业排名事件营销的案例有哪些
  • 检察门户网站建设方案seo网站查询工具
  • 万年历网站做如何制作网页教程
  • 东台网站建设搜索引擎收录
  • 无锡网站制作哪家服务好网站策划运营
  • 深圳做网站多少平台seo什么意思
  • wps2016怎么做网站网站推广优化方案
  • 做外贸网站案例怎么在网上做广告宣传
  • WordPress共享数据库谷歌seo公司
  • 网站建设需要考虑因素公司产品推广文案
  • 什么网站可以做任务领赏金百度一下你知道主页官网
  • 推荐定制型网站建设企业建站模板
  • 北京大型网站建设公司百度浏览官网
  • 网站建设网站建设的网络公司年度关键词
  • 学ps有用还是网页制作湖北网站seo策划