当前位置:网站首页>[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;
}
边栏推荐
- idea常用10个快捷键
- Base64 (conversion between string and Base64 string)
- (牛客多校二)G-Link with Monotonic Subsequence(构造题)
- HTB-Beep
- Basset: learning the regulatory code of the accessible genome with deep convolutional neural network
- Programming hodgepodge (II)
- LCP plug-in creates peer-to-peer 802.1ad interface
- Amazoncaptcha 95%成功率绕过亚马逊IP验证码
- Productivity tool in the new era -- flowus information flow comprehensive evaluation
- ABC 261.D - Flipping and Bonus ( DP )
猜你喜欢

Leetcode 204. 计数质数(太妙了)

Leetcode 204. count prime numbers (wonderful)

HTB-Arctic

The difference between function and task in SystemVerilog

Xiaomi 12s UTRA Leica watermark generation online tool

Difference between NPX and NPM

Talk about how redis handles requests
![(14)[驱动开发]配置环境 VS2019 + WDK10 写 xp驱动](/img/90/0d94d26be8128d77de65919763fda5.png)
(14)[驱动开发]配置环境 VS2019 + WDK10 写 xp驱动

CCID released the "Lake warehouse integrated technology research report", and Jushan database was selected as a typical representative of domestic enterprises

Productivity tool in the new era -- flowus information flow comprehensive evaluation
随机推荐
ECS is exclusive to old users, and the new purchase of the remaining 10 instances is as low as 3.6% off
同条网线电脑正常上网,手机连接wifi成功,但是无法访问互联网
A little experience about von Mises distribution
Airserver 7.3.0 Chinese version mobile device wireless transmission computer screen tool
(牛客多校二)J-Link with Arithmetic Progression(最小二乘法/三分)
idea常用10个快捷键
sqlilabs less-28~less-8a
Introduction summary of using unirx in unity
PostgreSQL learning 04 PG_ hint_ Plan installation and use, SQL optimization knowledge
R language ggpubr package ggarrange function combines multiple images and annotates_ Figure add annotation, annotation, annotation information for the combined image, and use the right parameter to ad
uniapp手机端uView的u-collapse组件高度init
C100: smallest hevc visual IOT MCU
Base64 (conversion between string and Base64 string)
Microservice configuration center Nacos
Amazoncaptcha 95%成功率绕过亚马逊IP验证码
(2022年牛客多校一)I-Chiitoitsu(期望DP)
Leetcode 0121. the best time to buy and sell stocks - simulation from back to front
leetcode/ 前 n 个数字二进制中 1 的个数
Programming hodgepodge (I)
Terminate 5g chip cooperation! The official response of Intel and zhanrui came