首页 > 其他 > 详细

BUPT复试专题—List

时间:2018-02-28 18:46:58      阅读:254      评论:0      收藏:0      [点我收藏+]

题目描述

在该LIST上实现3种操作

         1、append x在该LIST末尾添加x,x是32位整数

         2、pop删除该LIST末尾的数

         3、find i寻找第i个数,若i为负数表示寻找倒数第i个数,例如i = -1表示寻找倒数第一个

输入

首先一个数t表示以下有t个m

第一行输入一个m,表示有m条操作,接下来每行输入一条操作

 

输出

当输入find i时输出找到的数

样例输入

2 
5 
append 1 
append 2 
find 1 
find -1 
pop 
6 
append 1 
append 2 
append 3 
append 4 
find -2 
find 2

样例输出

1
2
3
2

来源

2015机考B题 

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
using namespace std;
int main()
{
    int num=0;
    scanf("%d",&num);
    while(num--)
    {
        int m,strnum=0;
        scanf("%d",&m);
        while(m--)
        {
            string temp,num1,num;
            char str[100];
            cin>>temp;
            if(temp[0]!=p)
                cin>>num1;
            if(temp[0]==a)//append
            {
                str[strnum]=num1[0];
                strnum++;
            }
            else if(temp[0]==f)//find
            {
                int x=num1[0]-48;
                if(x<0)
                {
                    x=num1[1]-48;
                    x=strnum-x+1;
                }
                cout<<str[x-1]<<endl;
            }
            else if(temp[0]==p)//pop
            {
                strnum--;
            }
        }
    }
    return 0;
}

 

BUPT复试专题—List

原文:https://www.cnblogs.com/dzzy/p/8485165.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!