串的一些操作,不包括kmp
来源:互联网 发布:java 语句 顺序 编辑:程序博客网 时间:2024/06/08 20:23
串的连接:
这里有串的创建,清空,输出,长度,(长度这里由于创建时s.length随着字符的输入不断改变(增加),所以长度函数就直接写s.length,如果前面没有一边输入,长度一边改变的代码,那在长度函数里需要自己进行编写,求出长度,也是由于之前长度有增加,所以后面for循环里的长度,直接i
#include<cstdio>#include<iostream>#include<algorithm>#include<stdlib.h>#include<cstring>#define MaxSize 54using namespace std;struct String{ char *ch; int length;};void createstr(String &s){ s.ch=(char*)malloc(sizeof(char)*54); s.length=0; for(int i=0; i<MaxSize; i++) { s.ch[i]=getchar(); s.length++; if(s.ch[i]=='\n') { break; } }}void print(String &s){ if(s.length==0) { printf("NULL\n"); } else { for(int i=0; i<s.length; i++) { if(s.ch[i]!='\n') { printf("%c ",s.ch[i]); } } printf("\n"); }}int strlength(String &s){ int l=s.length; return l-1; //减去一个\n的长度;}void connect(String &s,String &t,String &h){ h.ch=(char *)malloc(sizeof(char)*(s.length+t.length)); h.length=s.length+t.length; for(int i=0; i<s.length; i++) { h.ch[i]=s.ch[i]; } for(int i=0; i<h.length; i++) { h.ch[i+s.length-1]=t.ch[i]; }}void clear(String &s){ if(s.ch) { free(s.ch); s.ch=NULL; } s.length=0;}int main(){ String s,t,h; createstr(s); createstr(t); printf("s=%d\n",strlength(s)); printf("t=%d\n",strlength(t)); print(s); print(t); connect(s,t,h); print(h); clear(s); clear(t);}
阅读全文
0 0
- 串的一些操作,不包括kmp
- 串的操作(KMP算法实现)
- 一些扩展kmp的总结
- 一些扩展kmp的总结
- KMP算法的一些细节
- 数据结构图的基本操作--邻接表法(不包括深度、广度算法)
- 不包括单引号的正则表达式
- 进程阻塞的原因不包括
- 数据结构串的基本操作及KMP算法
- KMP 顺序串操作练习
- KMP 算法 自己的一些理解
- KMP模式匹配算法的一些理解
- 关于KMP的一些个人理解
- HDU和PKU的一些KMP题
- 【2】KMP算法的一些理解问题
- KMP算法的一些误区及其优化
- 获取桌面的大小(不包括任务栏)
- python输出不包括回车的方法
- PCD点云文件的读取
- 接口测试的另一种方式 – 接口测试平台
- WebSocket与Http关系
- PAT 甲级 1123. Is It a Complete AVL Tree (30)
- 089 定积分之双纽线、心形线、摆线
- 串的一些操作,不包括kmp
- PAT 甲级 1124. Raffle for Weibo Followers (20)
- Xcode9学习笔记13
- 【SSLGZ 2774】2017年10月19日提高组 青蛙 (jump)
- 【SSLGZ 2775】2017年10月19日提高组 新壳栈 (stk)
- 练习Go语言-HTTP压力测试.md
- python中字典的操作I
- 3155: Preprefix sum
- post方式采集网页数据-php采集网页-php爬虫视频教程7