当前位置:网站首页>Implementation of some basic operation codes of string
Implementation of some basic operation codes of string
2022-07-25 04:11:00 【Luish Liu】
Implementation of some basic operation codes of string
Fixed length sequential storage
#define MAXLEN 255 // Predefined maximum string length
typedef struct
{
char ch[MAXLEN]; // Each component stores one character
int length; // The actual length of the string
} SString;
substring
// substring . use sub Return string S No pos The length from characters is len The string of
bool SubString(SString &sub, SString S, int pos, int len)
{
if((pos + len - 1) > S.length) // Substring range is out of bounds
{
return false;
}
for(int i = pos; i < pos + len; pos++)
{
sub.ch[i - pos + 1] = S.ch[i];
}
sub.length = len;
return true;
}
Comparison operation
// Comparison string S And string T Size ; if S > T, Return value greater than 0; if S < T, Return value less than 0; if S = T, The return value is equal to 0
bool StrCompare(SString S, SString T)
{
for(int i = 1; i <= S.length && i <= T.length; i++)
{
if(S.ch[i] != T.ch[i])
{
return S.ch[i] - T.ch[i];
}
}
return S.length - T.length; // If all the characters scanned are the same, the long string will be larger
}
Positioning operation
// location . If the main string S And string exist in T Substring with the same value , Then return to his main string S The first place in ; Otherwise, the function value is 0
bool Index(SString S, SString T)
{
int i = 1, n = StrLength(S), m = StrLength(T);
SString Sub; // Temporary substring
while(i < (n-m+1))
{
SubString(sub, S, i, m);
if(StrCompare(S, T) != 0)
{
++i;
}
else
{
return i; // Returns the position of the substring in the main string
}
}
return 0; // S There is no and T Equal substrings
}
边栏推荐
- Emergency response stack
- [Flink] submit the jar package to the Flink cluster and run it
- Xrrunner, a domestic performance testing tool for palm smart, officially unveiled qecon
- Customized view considerations
- 301. Delete invalid brackets
- How should enterprise users choose aiops or APM?
- ES(8.1)认证题目
- An article takes you quickly to learn flex layout
- Detailed explanation of kubernetes network plug-in - flannel chapter
- Current characteristics of steering gear with great resistance
猜你喜欢

It took me 2 years from Foxconn assembly line to Tencent software testing post~

226. Flip binary tree DFS method

C language file operation

Multithreading advanced Step2

Huawei cloud from entry to actual combat | cloud rapid site establishment service and enterprise host security service

Detailed explanation of kubernetes network plug-in - flannel chapter

DIY can decorate the mall system, you can also have!

MySQL select query part 2

What are the models of asemi from the manufacturer of rectifier bridge and how about the electroplating process of the manufacturer of rectifier bridge?

Jenkins continues to integrate entry to mastery
随机推荐
Wechat applet access wechat payment process
Roleapp focuses on Web3 and opens the door of Web3 with the key of "data can be held"
Analytic hierarchy process of MATLAB
01_ Education 3
It took me 2 years from Foxconn assembly line to Tencent software testing post~
Construction of data center (I): background of the emergence of data center
Which securities company do retail investors choose for stock speculation? Is it safe to open an account on your mobile phone
Niuke interview high frequency list (group 1) difficulty: simple & medium
Use "display: flex; justify content: Center; align items: Center;" Solve the problem that the streaming grid layout cannot be centered
应急响应全栈
Internship in 2022
Current characteristics of steering gear with great resistance
ES(8.1)认证题目
Implementation of logistics repair reporting system based on SSM
Max matrix and JS
Force deduction question 3
Implementing DDD based on ABP -- domain logic and application logic
Postgraduate entrance examination experience
Pandora IOT development board learning (RT thread) - Experiment 16 WiFi module experiment (learning notes)
[Flink] aggregation operator