第八周项目二
来源:互联网 发布:centos 7 yum 安装svn 编辑:程序博客网 时间:2024/05/17 00:17
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #include <stdio.h>
- #include "../sqstring.h"
- void Trans(SqString &s, char c1, char c2)
- {
- int i;
- for (i=0; i<s.length; i++)
- if (s.data[i]==c1)
- s.data[i]=c2;
- }
-
- int main()
- {
- SqString s;
- StrAssign(s, "messages");
- Trans(s, 'e', 'a');
- DispStr(s);
- return 0;
- }
-
-
-
-
-
- #include <stdio.h>
- #include "../sqstring.h"
- void Invert(SqString &s)
- {
- int i;
- char temp;
- for (i=0; i<s.length/2; i++)
- {
- temp = s.data[i];
- s.data[i]=s.data[s.length-i-1];
- s.data[s.length-i-1] = temp;
- }
- }
-
- int main()
- {
- SqString s;
- StrAssign(s, "abcdefg");
- Invert(s);
- DispStr(s);
- return 0;
- }
-
-
-
-
- #include <stdio.h>
- #include "../sqstring.h"
-
- void DellChar(SqString &s, char c)
- {
- int k=0, i=0;
- while(i<s.length)
- {
- if(s.data[i]==c)
- k++;
- else
- s.data[i-k]=s.data[i];
- i++;
- }
- s.length -= k;
- }
-
- int main()
- {
- SqString s;
- StrAssign(s, "message");
- DellChar(s, 'e');
- DispStr(s);
- return 0;
- }
-
-
-
-
-
- SqString CommChar(SqString s1,SqString s2);
-
-
- #include <stdio.h>
- #include "../sqstring.h"
- SqString CommChar(SqString s1,SqString s2)
- {
- SqString s3;
- int i,j,k=0;
- for (i=0; i<s1.length; i++)
- {
- for (j=0; j<s2.length; j++)
- if (s2.data[j]==s1.data[i])
- break;
- if (j<s2.length)
- {
- s3.data[k]=s1.data[i];
- k++;
- }
- }
- s3.length=k;
- return s3;
- }
-
- int main()
- {
- SqString s1, s2, s;
- StrAssign(s1, "message");
- StrAssign(s2, "agent");
- s = CommChar(s1, s2);
- DispStr(s);
- return 0;
- }
运行结果:
学习心得:学会了运用顺序存储方式存储串。