#include<bits/stdc++.h>
using namespace std;
struct line{
int num;
line * next;
};
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin>>n>>m;
line *a;
a=new line;
a->num=1;
a->next=NULL;
line* current=a;
for(int i=1;i<n;i++){
current->next=new line;
current=current->next;
current->num=i+1;
current->next=NULL;
}
while(m--){
int k;
cin>>k;
line* cur=a;
line *pre;
while(cur!=NULL&&(cur->num)<k){
pre=cur;
cur=cur->next;
}
if(cur==NULL||(cur->num)>k){
cout<<"0u0 ...... ?"<<'\n';
}
else {
auto temp=cur;
cur=cur->next;
if(cur==NULL){
cout<<"0u0 ...... ?"<<'\n';
continue;
}
cout<<cur->num<<'\n';
auto next_n=cur->next;
delete cur;
temp->next=next_n;
}
}
}
#include<bits/stdc++.h>
using namespace std;
struct line{
int num;
line * next;
};
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin>>n>>m;
line *a;
a=new line;
a->num=1;
a->next=NULL;
line* current=a;
for(int i=1;i<n;i++){
current->next=new line;
current=current->next;
current->num=i+1;
current->next=NULL;
}
while(m--){
int k;
cin>>k;
line* cur=a;
line *pre;
while(cur!=NULL&&(cur->num)<k){
pre=cur;
cur=cur->next;
}
if(cur==NULL||(cur->num)>k){
cout<<"0u0 ...... ?"<<'\n';
}
else {
auto temp=cur;
cur=cur->next;
if(cur==NULL){
cout<<"0u0 ...... ?"<<'\n';
continue;
}
cout<num<<'\n';
auto next_n=cur->next;
delete cur;
temp->next=next_n;
}
}
}
這樣一個一個找太慢了,O(n^2)
用二分搜尋法