zoukankan      html  css  js  c++  java
  • 算法与数据结构实验题 3.2 文档

    1、题目:

    ★实验任务 TonyY 是一个 word 小白,今天他对 word 中撤销和恢复功能特别感兴趣,玩 耍了一个上午(mdzz~),现在他知道了它们的功能和快捷键: 撤销:ctrl+z,可以撤销最近 1 次之前的恢复和 input 操作。 恢复:ctrl+y,可以恢复最近 1 次之前的撤销操作,但是 input 操作之前的 撤销操作不能被恢复。 当然,TonyY 还要往里写东西,操作格式为 input str(长度 m 1=<m<=30)。 现在他对 word 玩耍了起来,想知道玩耍完的结果,你可以帮助他吗?
    ★数据输入
    输入第一行为一个正整数 n(0<=n<=10000),表示 TonyY 的操作次数。 接下来 n 行,为上述的操作之一。 其中可能有不合法操作,直接跳过即可。
    ★数据输出
    输出 word 中的内容,字符串间用空格隔开,如果 word 为空,输出”No output”

    2、代码:

    #include<iostream>
    #include<string>
    using namespace std;
    int main()
    {
    	int n;
    	cin>>n;
    	int i,j=0,k;
    	string str,data,a[10005];
    	for(i=0; i<n; i++)
    	{
    		cin>>str;
    		if(str=="input")
    		{
    			
    			cin>>a[++j];
    			k=j;
    		}
    		if(str=="ctrl+z")
    		{
    			if(j>0)
    			{
    				--j;
    			}
    		}
    		if(str=="ctrl+y")
    		{
    			if(j<k)
    			{
    				++j;
    			}
    		}
    	}
    	if(j==0)
    	{
    		cout<<"No output"<<endl;
    	}
    	else
    	{
    		for(i=1; i<=j; i++)
    		{
    			if(i<j)
    			{
    				cout<<a[i]<<" ";
    			}
    			if(i==j)
    			{
    				cout<<a[i]<<endl;
    			}
    		}
    		
    	}
    
    	return 0;
    }
  • 相关阅读:
    eclipse/myeclipse介绍
    HDU 5802 Windows 10
    LaTeX test
    数据结构2 静态区间第K大/第K小
    数据结构1 「在线段树中查询一个区间的复杂度为 $O(log N)$」的证明
    HDU 1007 Quoit Design
    HDU 5761 Rower Bo
    hihocoder #1341 Constraint Checker
    HDU #5733 tetrahedron
    hihocoder #1327
  • 原文地址:https://www.cnblogs.com/laixiaolian/p/5914385.html
Copyright © 2011-2022 走看看