当前位置:网站首页>[daily practice] day (14)
[daily practice] day (14)
2022-07-25 05:45:00 【Xiao Tang xuezha】
List of articles
One 、 choice question
eg1


eg2

eg3

eg4

eg4

eg5

eg6

eg7

eg8

eg9

eg10

eg11

eg12

eg13

eg14

Two 、 Programming questions
eg1

【 Their thinking 】:
This problem needs to be solved by dynamic programming ,MCS[i][j] Record short string s1 front i Characters and long strings s2 front j The length of the longest substring of characters , Initialize all values to 0. When s1[i-1] = s2[j-1] when ,MCS[i][j] = MCS[i - 1][j - 1] + 1, Here we use an extra value start To record the longest substring in a short string s1 The starting position in ,maxlen Record the length of the current longest substring , When MCS[i][j] >maxlen when ,maxlen = MCS[i][j], be start = i - maxlen ; files s1[i-1] != s2[j-1] No operation is required , Finally get substr(start, maxlen) It's what you want
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string GetSubStr(string& s1, string& s2)
{
if(s1.size() > s2.size())
swap(s1, s2);
int len1 = s1.size();
int len2 = s2.size();
// Open up one more row and one more column , Initialize to 0
vector<vector<int>> MSC(len1+1, vector<int>(len2+1, 0));
int max_size = 0;
int start = 0;
for(int i = 1; i < len1; ++i)
{
for(int j = 1; j < len2; ++j)
{
if(s2[j-1] == s1[i-1])
MSC[i][j] = MSC[i-1][j-1] + 1;
if(MSC[i][j] > max_size)
{
max_size = MSC[i][j];
start = i - max_size;
}
}
}
return s1.substr(start, max_size);
}
int main()
{
string s1;
string s2;
while(cin >>s1 >> s2)
{
string ret = GetSubStr(s1, s2);
cout << ret << endl;
}
return 0;
}
边栏推荐
- Microservice - hystrix fuse
- 50: Chapter 5: develop admin management service: 3: develop [query whether the admin user name already exists, interface]; (this interface can only be called when logging in; so we have written an int
- (牛客多校二)J-Link with Arithmetic Progression(最小二乘法/三分)
- R language obtains the data row where the nth maximum value of the specified data column is located in the data.table data
- 暑期总结2
- (Niuke multi School II) G-LINK with monotonic subsequence (construction question)
- Singing "Seven Mile fragrance" askew -- pay tribute to Jay
- Big talk · book sharing | Haas Internet of things device cloud integrated development framework
- Analyzing the principle of DNS resolution in kubernetes cluster
- (Niuke multi School II) j-link with arithmetic progress (least square method / three points)
猜你喜欢

(2022牛客多校二)K-Link with Bracket Sequence I(动态规划)

QT qtextedit setting qscrollbar style sheet does not take effect solution

(牛客多校二)J-Link with Arithmetic Progression(最小二乘法/三分)

Leetcode 204. count prime numbers (wonderful)

Leetcode 202. 快乐数(一点都不快乐)

HTB-Beep

AirServer 7.3.0中文版手机设备无线传送电脑屏幕工具

HTB-Arctic

Promise implementation

50:第五章:开发admin管理服务:3:开发【查询admin用户名是否已存在,接口】;(这个接口需要登录时才能调用;所以我们编写了拦截器,让其拦截请求,判断用户是否是登录状态;)
随机推荐
Dynamic planning learning notes
Airserver 7.3.0 Chinese version mobile device wireless transmission computer screen tool
Switch NPM source to private source library
Array programming problem of CSDN programming challenge
R language Visual scatter diagram, geom using ggrep package_ text_ The repl function avoids overlapping labels between data points (set the hJust parameter to show that labels of all data points are a
2020icpc Jiangxi warm up e.robot sends red packets (DFS)
Vim配置Golang开发环境
新时代生产力工具——FlowUs 息流全方位评测
leetcode/ 前 n 个数字二进制中 1 的个数
Codeforces Round #809 (Div. 2)
HTB-Beep
HTB-Devel
传输线理论之相速、相位等的概念
leetcode/二进制加法
10、渲染基础
HTB-Arctic
flex布局常用属性总结
Softing pnGate系列网关:将PROFIBUS总线集成到PROFINET网络
暑期总结2
Big talk · book sharing | Haas Internet of things device cloud integrated development framework