附上Code 但是記憶體區段錯誤的原因是什麼呢, TLE的話可能要改成scanf printf
#include <iostream>
using namespace std;
struct kevin{
long long int value;
kevin *ptr;
};
int main(){
kevin *head, *temp, *current;
long long int n,m,kill;
while(cin>>n>>m){
if(n==0)
break;
head = new kevin;
head->value=1;
head->ptr=NULL;
current=head;
for(int i=2;i<=n;i++){
temp = new kevin;
current->ptr=temp;
current=temp;
current->value=i;
current->ptr=NULL;
}
for(int i=1;i<=m;i++){
current=head;
cin>>kill;
while(current->value!=kill){
current=current->ptr;
}
if(current->ptr==NULL)
cout<<"0u0 ...... ?"<<endl;
else{
temp=current->ptr;
cout<<temp->value<<endl;
current->ptr=temp->ptr;
delete temp;
}
}
}
return 0;
}
附上Code 但是記憶體區段錯誤的原因是什麼呢, TLE的話可能要改成scanf printf
#include
using namespace std;
struct kevin{
long long int value;
kevin *ptr;
};
int main(){
kevin *head, *temp, *current;
long long int n,m,kill;
while(cin>>n>>m){
if(n==0)
break;
head = new kevin;
head->value=1;
head->ptr=NULL;
current=head;
for(int i=2;i<=n;i++){
temp = new kevin;
current->ptr=temp;
current=temp;
current->value=i;
current->ptr=NULL;
}
for(int i=1;i<=m;i++){
current=head;
cin>>kill;
while(current->value!=kill){
current=current->ptr;
}
if(current->ptr==NULL)
cout<<"0u0 ...... ?"<<endl;
else{
temp=current->ptr;
cout<value<<endl;
current->ptr=temp->ptr;
delete temp;
}
}
}
return 0;
}
忘記看到
如果 "這個這個人已經死了" or 他是最後一個人
請輸出 "0u0 ...... ?"
已解
附上Code 但是記憶體區段錯誤的原因是什麼呢, TLE的話可能要改成scanf printf
#include
using namespace std;
struct kevin{
long long int value;
kevin *ptr;
};
int main(){
kevin *head, *temp, *current;
long long int n,m,kill;
while(cin>>n>>m){
if(n==0)
break;
head = new kevin;
head->value=1;
head->ptr=NULL;
current=head;
for(int i=2;i<=n;i++){
temp = new kevin;
current->ptr=temp;
current=temp;
current->value=i;
current->ptr=NULL;
}
for(int i=1;i<=m;i++){
current=head;
cin>>kill;
while(current->value!=kill){
current=current->ptr;
}
if(current->ptr==NULL)
cout<<"0u0 ...... ?"<<endl;
else{
temp=current->ptr;
cout<value<<endl;
current->ptr=temp->ptr;
delete temp;
}
}
}
return 0;
}
忘記看到
如果 "這個這個人已經死了" or 他是最後一個人
請輸出 "0u0 ...... ?"
已解
改成scanf printf 後仍然會TLE 求救
#include <stdio.h>
struct kevin{
long long int value;
kevin *ptr;
};
int main(){
long long n,m,kill;
while(scanf("%d%d",&n,&m)!=EOF){
kevin *head, *temp, *current;
head = new kevin;
head->value=1;
head->ptr=NULL;
current=head;
for(int i=2;i<=n;i++){
temp = new kevin;
current->ptr=temp;
current=temp;
current->value=i;
current->ptr=NULL;
}
for(int i=1;i<=m;i++){
current=head;
scanf("%d",&kill);
while(current!=NULL){
if(current->value==kill)
break;
else
current=current->ptr;
}
if(current==NULL||current->ptr==NULL)
printf("0u0 ...... ?\n");
else{
temp=current->ptr;
printf("%d\n",temp->value);
current->ptr=temp->ptr;
delete temp;
}
}
}
return 0;
}