link能不能自动求出一段话中最长的重复的两句话?

问题描述

link能不能自动求出一段话中最长的重复的两句话?

link能不能自动求出一段话中最长的重复的两句话?

解决方案

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = @"Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate -- we can not consecrate -- we can not hallow -- this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -- that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the people, by the people, for the people, shall not perish from the earth.";
            var query = Enumerable.Range(0, s.Length).OrderBy(x => s.Substring(x)).ToList();
            string max = "";
            for (int i = 1; i < query.Count; i++)
            {
                string s1 = s.Substring(query[i - 1]);
                string s2 = s.Substring(query[i]);
                string same = string.Concat(s1.Zip(s2, (x, y) => x == y ? x : '').TakeWhile(x => x != ''));
                if (same.Length > max.Length)
                    max = same;
            }
            Console.WriteLine(max);
        }
    }
}

解决方案二:

输出

  dedicated to the
请按任意键继续. . .
时间: 2024-12-20 14:53:46

link能不能自动求出一段话中最长的重复的两句话?的相关文章

c# 代码 注释-C# 求解释 两句话问好处

问题描述 C# 求解释 两句话问好处 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Collections; namespace 汉诺塔递归 { public partial class F

如何从文本框中输入的出生日期自动求出当前年龄(岁数)?

问题描述 1,在text1中输入职工出生日期,格式为"yyyy-MM-dd"2.在text2中自动显示出年龄,即多大岁数. 解决方案 解决方案二:txt2.Text=(DateTime.Now.Year-DateTime.Parse(txt1.Text).Year).ToString();如果需要将月份四舍五入就是DateTime.Now.Subtract(DateTime.Parse(txt1.Text)).TotalYears.ToString(F0);解决方案三:哈哈,没注意看T

求字符串中最长无重复字符的子串

题目:求一个字符串中最长的没有重复字符的子串. 方法一:穷举法,使用2重外循环遍历所有的区间,用2重内循环检验子串是否符合"无重复字符"这一要求.其中外层循环i.j 遍历所有的下标,m.n是内层循环,检查区间[i,j]是否符合要求.空间复杂度是O(1),时间复杂度O(N^4). //O(N^4)的时间复杂度 int max_unique_substring1(char * str) { int maxlen = 0; int begin = 0; int n = strlen(str)

求出一个排序二叉树中结点度数为一的结点个数

#include<stdio.h> #include<iostream.h> #include<conio.h> #include<malloc.h> #include<stdlib.h> #define ERROR 0 #define STACK_INIT_SIZE 100 #define OVERFLOW -1 #define FALSE 0 #define TRUE 1 #define OK 1 int i=0;   struct  tre

二维数组-请问这段代码中最后输出元素的时候,有必要加个空格吗?

问题描述 请问这段代码中最后输出元素的时候,有必要加个空格吗? static void Main(string[] args) { int[,] score = new int[3, 5]; score[0, 0] = 103; score[1,4] = 80; for (int i = 0; i <3; i++) { for (int j = 0; j < 5; j++) { Console.Write(score[i, j] + " "); Console.WriteL

C++课程设计老师说我没有用到类 求指教这段代码要怎么修改加上类

问题描述 C++课程设计老师说我没有用到类 求指教这段代码要怎么修改加上类 #include #include #include using namespace std; const double pi = 3.14159265; const double e = 2.718281828459; const int SIZE = 1000; typedef struct node//为了处理符号而建立的链表(如: 1+(-2)) { char data; node *next; }node; t

vc++获取当前使用IE的URL路径并自动打印出相应的网址

这是关于获取当IE所打开的URL地址(VC++),并且自动打印出相应的网址源代码内容: //将这个放入你的头文件stdafx.h中 #import <mshtml.tlb> #import <shdocvw.dll> void CGetIESrcDlg::GetRunningIESrc() { SHDocVw::IShellWindowsPtr m_spSHWinds; CoInitialize(NULL); if(m_spSHWinds.CreateInstance(__uuid

如何在wps表格中求出总分

  在wps表格中求出总分的方法: 写入数据,将鼠标定在总分下的单元格中,单元格必须是要定好位置,不然数值可能会有错误. 单击上方菜单栏中的求和按钮摆选择求和,选择求值区域, 只需要将第一行的求好,然后将鼠标移动到单元格的右下角,变成黑色十字架的形状,双击两下以下的数据便会自动求值. 求最大值是单击菜单栏上的求和按钮.选择最大值,同样的光标的位置要定在最大值右边单元格中,求好后将鼠标移动到单元格的右下角,变成黑色十字架的形状,向右拖拽数据便会自动求值. 求最小值也是单击菜单栏上的求和按钮.选择最

wps表格如何求出总分

  在wps表格中求出总分的方法: 写入数据,将鼠标定在总分下的单元格中,单元格必须是要定好位置,不然数值可能会有错误. 单击上方菜单栏中的求和按钮摆选择求和,选择求值区域, 只需要将第一行的求好,然后将鼠标移动到单元格的右下角,变成黑色十字架的形状,双击两下以下的数据便会自动求值. 求最大值是单击菜单栏上的求和按钮.选择最大值,同样的光标的位置要定在最大值右边单元格中,求好后将鼠标移动到单元格的右下角,变成黑色十字架的形状,向右拖拽数据便会自动求值. 求最小值也是单击菜单栏上的求和按钮.选择最