操作系统大模拟(乐学)

操作系统大模拟

#include<iostream>
#include<cstdio>
#include<string>
#include<list>
#include<iterator>
#include<cstring>
#include<queue>

using namespace std;

list<string>orig;

int main()
{
	string str;
	string str_temp1,str_temp2;
	list<string>::iterator pos;
	list<string>::iterator pos_target;
	string::iterator sch, cpy;
	string::size_type str_pos(0);
	priority_queue<int>numb;
	char op;
	char temp;
	int str_no;
	int str_no_temp;
	int i;
	int flag;
	flag = 0;
	while (1)
	{
		getline(cin, str);
		if (str == "[Text]")
		{
			str.clear();
			continue;
		}
		else if (str == "[/Text]")
		{
			str.clear();
			break;
		}
		else
		{
			orig.push_back(str);
			str.clear();
		}
	}
	while (1)
	{
		str.clear();
		str_temp1.clear();
		str_temp2.clear();
		if ((op = cin.get()) == EOF)
		{
			break;
		}
		temp = getchar();
		if (op == 'i')
		{
			cin>>str_no;
			temp = getchar();
			getline(cin, str_temp1);
			while (1)
			{
				if ((str_pos = str_temp1.find("\\/")) == string::npos)
				{
					break;
				}
				str_temp1.replace(str_pos, 2, "/");
			}
			if (str_no > orig.size())
			{
				orig.push_back(str_temp1);
			}
			else
			{
				pos = orig.begin();
				for (i = 1; i < str_no; i++)
				{
					pos++;
				}
				orig.insert(pos, str_temp1);
			}
		}
		else if (op == 'c')
		{
			getline(cin, str);
			sch = str.begin();
			cpy = str.end();
			str_no = str.size();
			for (i = 0; i < str_no; i++)
			{
				
				if (str[i] == '/')
				{
					if (i == 0)
					{
						continue;
					}
					else if (str[i - 1] == '\\')
					{
						sch++;
						continue;
					}
					else
					{
						str[i] = '\0';
						sch++;
						while (1)
						{
							if (sch == cpy)
							{
								break;
							}
							str_temp1 = str_temp1 + *sch;
							sch++;
						}

					}
				}
				if (sch == cpy)
				{
					break;
				}
				sch++;
			}
			while (1)
			{
				if ((str_pos = str.find("\\/")) == string::npos)
				{
					break;
				}
				str.replace(str_pos, 2, "/");
			}
			while (1)
			{
				if ((str_pos = str_temp1.find("\\/")) == string::npos)
				{
					break;
				}
				str_temp1.replace(str_pos, 2, "/");
			}
			sch = str.begin();
			while (1)
			{
				if (*sch == '\0')
				{
					break;
				}
				str_temp2 = str_temp2 + *sch;
				sch++;
			}
			pos = orig.begin();
			while (1)
			{
				if (pos == orig.end())
				{
					break;
				}
				while (1)
				{
					if ((str_pos = ((*pos).find(str_temp2))) == string::npos)
					{
						break;
					}
					(*pos).replace(str_pos, str_temp2.length(), str_temp1);
				}
				pos++;
			}
		}
		else if (op == 'd')
		{
			cin >> str_no;
			temp = getchar();
			pos = orig.begin();
			if (str_no > orig.size())
			{
				continue;
			}
			else
			{
				for (i = 1; i < str_no; i++)
				{
					pos++;
				}
				orig.erase(pos);
			}
		}
		else if (op == 'f')
		{
			cin >> str_no;
			while (1)
			{
				if (str_no > orig.size())
				{
					temp = getchar();
				}
				else break;
				if (temp == '\n')
				{
					break;
				}
				else
				{
					cin >> str_no;
				}
			}
			if (temp == '\n')
			{
				continue;
			}
			pos_target = orig.begin();
			for (i = 1; i < str_no; i++)
			{
				pos_target++;
			}
			while (1)
			{
				temp = getchar();
				if (temp == '\n')
				{
					break;
				}
				cin >> str_no_temp;
				if (str_no_temp > orig.size())
				{
					continue;
				}
				else
				{
					pos = orig.begin();
					for (i = 1; i < str_no_temp; i++)
					{
						pos++;
					}
					*pos_target = *pos_target + *pos;
					numb.push(str_no_temp);
				}
			}
			while (1)
			{
				if (numb.size() == 0)
				{
					break;
				}
				pos = orig.begin();
				for (i = 1; i < numb.top(); i++)
				{
					pos++;
				}
				orig.erase(pos);
				numb.pop();
			}
		}
		else if (op == 'q')
		{
			temp = getchar();
			cin >> str_no;
			temp = getchar();
			getline(cin, str);
			while (1)
			{
				if ((str_pos = str.find("\\/")) == string::npos)
				{
					break;
				}
				str.replace(str_pos, 2, "/");
			}
			if (flag == 0)
			{
				pos = orig.begin();
				while (1)
				{
					if (pos == orig.end())
					{
						break;
					}
					printf("%s\n", (*pos).c_str());
					pos++;
				}
				flag = 1;
			}
			pos = orig.begin();
			for (i = 1; i < str_no; i++)
			{
				pos++;
			}
			if ((str_pos = ((*pos).find(str))) == string::npos)
			{
				printf("No\n");
			}
			else printf("Yes\n");
		}
	}
	if (flag == 0)
	{
		pos = orig.begin();
		while (1)
		{
			if (pos == orig.end())
			{
				break;
			}
			printf("%s\n", (*pos).c_str());
			pos++;
		}
		flag = 1;
	}
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值