当前位置:网站首页>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
}
边栏推荐
- Array the same value of key and merge the value value (collation)
- MySQL select query part 2
- Large screen visual adaptation file
- 有个问题想请教下,我想用来同步数据库,但我看他是根据mysql 的binlog同步的,如果是大表,一
- 弹性布局(display:flex下 align-content、justify-content、align-items三个属性的作用和效果
- Localization distillation for dense object detection cvpr2022
- Execution flow control of shell
- Deep learning method of building a model from zero
- Which securities company do retail investors choose for stock speculation? Is it safe to open an account on your mobile phone
- [Flink] protocol operator reduce
猜你喜欢

How should enterprise users choose aiops or APM?

Press the switch for the minimum number of times to turn on all lights

Fifth day of force deduction

Solve "nothing added to commit but untracked files present"“

Analytic hierarchy process of MATLAB

Yuntu says digital asset chain: your God of digital asset property protection

Servlet个人实操笔记(一)

Xrrunner, a domestic performance testing tool for palm smart, officially unveiled qecon

Wechat applet application development (I)

C language file operation
随机推荐
Jenkins continues to integrate entry to mastery
应急响应全栈
使用 “display: flex;justify-content: center;align-items: center; ” 解决流式栅格布局无法居中的问题
[Flink] transform operator flatmap
JS absolute minimum value of the sum of Huawei od two numbers
[Flink] protocol operator reduce
Hbuilderx eslint configuration
Use "display: flex; justify content: Center; align items: Center;" Solve the problem that the streaming grid layout cannot be centered
Shell string
Fifth day of force deduction
301. Delete invalid brackets
EMQ Yingyun technology was successfully selected into the 2022 "cutting edge 100" list of Chinese entrepreneurs
Interview question 05.06. integer conversion
Customized view considerations
Nested if selection structure and switch selection structure
226. Flip binary tree DFS method
How to cancel and exit revision mode for word
Creativity: presentation of AI oil paintings with high imitation mineral pigments
Aggregate payment meets the needs of various industries to access a variety of payments
Debezium series: in depth interpretation of important JMX indicators of debezium