原题地址
记录一下自己通过查百度而写出来的代码
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iomanip>
#include <string.h>
#include <list>
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
/*struct shi
{
int x;
int T;
} s[100000];
int cmp(shi a,shi b)
{
return a.x<b.x;
}
long long cmd(long long a, long long b)
{
return a > b;
}*/
//int m , n,sum,k;
/*
typedef struct node {
int num;
struct node *next;
}student;
student * creatlist(int b){
student *head = new student;
student *pre = head;
for(int i=1;i<=b;i++){
student *p = new student ;
p->num = i;
pre->next = p;
pre = p;
p->next = NULL;
}
pre->next = head->next;
return head;
};
void kill(struct node *head , int n){
while(head->next!=head){
for(int i=1;i<=n-1;i++){
head = head->next;
}
head->next = head->next->next;
}
cout<<head->num<<endl;
}*/
int main()
{
int m , n;
cin >>m >>n;
list<int> lis;
for(int i=1;i<=m;i++){
int j;
cin >>j;
lis.push_back(j);
}
/*for(auto it= lis.begin();it != lis.end();it++)
cout<<*it<<endl;*/
for(int i=0;i<n;i++){
int j,falg=1;
list<int>::iterator it=lis.begin();
cin >>j;
it = find(lis.begin(),lis.end(),j);
if(it==lis.begin()){
falg=0;
cout<<" ";
}
else{
advance(it , -1);//主要是这里记录一下
if(it!=lis.begin())
cout<<*it;
}
cout<<" ";
it = find(lis.begin(),lis.end(),j);
advance(it, 1);
if(it!=lis.end())
cout<<*it;
cout<<endl;
}
/*
node *head = creatlist(m);
kill(head,n);*/
return 0;
}
/***************************************************
User name: gpytql
Result: Accepted
Take time: 0ms
Take Memory: 196KB
Submit time: 2019-08-08 09:13:03
****************************************************/