放图镇楼:
模拟的中间的传输数据那块
思路
用string类型实现,加在首部就是string 1 + string 2(1为首部)
加在尾部同理
减去首部和尾部用了点技巧
减去首部,查找首部最后一个字,然后把之后的数据都前移
减去尾部,找到尾部第一个字,置为'\0'
代码
//TCP/IP协议的报文的传输模拟 应用层Y 传输层C 网络层 W 数据链路层 S+Tail 物理层 WL
#include <iostream>
using namespace std; //注意各个函数是对S进行操作,而不是简单的打印
char s[1000];
void InsertIn(char temp){
int len = strlen(s);
s[len+1]='\0';
for(int i=len-1;i>=0;i--){
s[i+1]=s[i];
}
s[0] =temp;
}
void DeleteFront(){
int len = strlen(s);
for(int i=1;i<len;i++){
s[i-1] = s[i];
}
s[len-1]='\0';
cout<<s<<endl;
}
void AddY(char s[]){ //在字符串前面插入一个Y
char temp='Y';
InsertIn(temp);
cout<<s<<endl;
}
void AddC(char *s){ //在字符串前面插入一个C
char temp='C';
InsertIn(temp);
cout<<s<<endl;
}
void AddW(char *s){ //在字符串前面插入W
char temp='W';
InsertIn(temp);
cout<<s<<endl;
}
void AddS(char *s){ //在字符串前面插入S
char temp='S';
InsertIn(temp);
cout<<s<<endl;
}
void AddWL(char *s){ //在字符串前面插入WL 和在后面添加tail
char temp='L';
InsertIn(temp);
cout<<s<<endl;
}
/*void CutWL(char *s){ //在字符串前面删除WL 和在后面删除tail
}
void CutS(char *s){
}
void CutW(char *s){
}
void CutC(char *s){
}
void CutY(char *s){
}*/
void main()
{
cin>>s;
AddY(s);
AddC(s);
AddW(s);
AddS(s);
AddWL(s);
for(int i=0;i<5;i++)
DeleteFront();
}