当前位置:网站首页>Written examination mandatory training day 20
Written examination mandatory training day 20
2022-07-21 19:51:00 【Curry won't throw three points】
Programming questions
Violence enumeration
- We find each seed sequence from a shorter string each time ( Successive ), To compare in a longer string , Maintain the longest length every time , If it is greater than the longest length , Just compare this string
- Need to distinguish between long and short strings
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc =new Scanner(System.in); String str1=sc.nextLine(); String str2=sc.nextLine(); String str11=str1.length()<str2.length()?str1:str2; String str22=str1.length()<str2.length()?str2:str1; //str1 Is a shorter string str2 Is a long string int max=0; for (int i = 0; i <str11.length(); i++) { for (int j = i+1; j <=str11.length() ; j++) { if (str22.contains(str11.substring(i,j))&&j-i>max){ max=j-i; } } } System.out.println(max); } }
Dynamic programming
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); String str1=sc.nextLine(); String str2=sc.nextLine(); int row=str1.length(); int column=str2.length(); int dp[][]=new int[row+1][column+1]; int max=0; //dp[i][j] Express str1 Before i Two strings and str2 Before j Maximum common string length of strings //base case for (int i = 0; i <=row; i++) { dp[i][0]=0; } for (int i = 0; i <=column; i++) { dp[0][i]=0; } for (int i = 1; i <=row; i++) { for (int j = 1; j <=column ; j++) { if(str1.charAt(i-1)!=str2.charAt(j-1)){ dp[i][j]=0; }else { dp[i][j]=dp[i-1][j-1]+1; } max=Math.max(max,dp[i][j]); } } System.out.println(max); } }
边栏推荐
猜你喜欢
ImportError: DLL load failed while importing win32gui: 找不到指定的模块。
动作活体检测能力,构建安全可靠的支付级“刷脸”体验
全志A40i开发板硬件说明书——100%国产+工业级方案(上)
Electromagnetic field and electromagnetic wave experiment three familiar with the application of Mathematica software in the field of electromagnetic field
CV (4)- Backpropagation and Neural Networks
The 22 pictures show you in-depth analysis of prefix, infix, suffix expressions and expression evaluation
Sequence model (I) - cyclic sequence model
426. 将二叉搜索树转化为排序的双向链表
Attack and defense world ----- favorite_ number
Project Management Maturity Model and project quantitative management
随机推荐
受众分析与卸载分析全面升级,HMS Core分析服务6.6.0版本上新
Web3 traffic aggregation platform starfish OS gives players a new paradigm experience of metauniverse
动作活体检测能力,构建安全可靠的支付级“刷脸”体验
629. K个逆序对数组
45. Record the training process of orienmask and the process of deploying Yunshi technology depth camera
Remove unnecessary fields
CV (4)- Backpropagation and Neural Networks
Click the model mode box and the other areas will not disappear except the mode box
维密萎靡,曾经“性感”现在真的“凉了”!
[uncover secrets] secret of project manager's resumption with an annual salary of 1million
(2) Dameng database matching
shell中算术运算小结
Common function test checkpoints and use case design ideas
我的UI自動化測試的感悟
C language learning
全志A40i开发板硬件说明书——100%国产+工业级方案(下)
Ens reading notes
STM32——ADC读取光敏传感器控制LED灯,看门狗中断
Assertion failed: inputs. At (2). Is Poids
Common tools and test methods for interface testing