Carrot_killer @ 2021-03-06 15:29:07
本题链表不是最优解,只不过我想趁机复习一下链表,但是没想到输出全是0,并且检查不出哪里错了,请大佬们帮忙检查一下,谢谢!
#include<iostream>
#include<cstring>
using namespace std;
struct node{
long now;
long data=0;
node *next=NULL;
}sheif[100001];
long long x,y,z,n,q,id;
int main(){
cin>>n>>q;
for(int i=1;i<=q;i++){
cin>>id;
if(id==1){
cin>>x>>y>>z;
node head=sheif[x];
bool found=false;
while(head.next!=NULL&&!found){
if(y=head.now){
head.data+=z;
found=true;
break;
}
head=*head.next;
}
if(sheif[x].now==y&&!found){
sheif[x].data+=z;
found=true;
}
if(head.next==NULL&&!found){
node p;
p.data=z;
p.next=NULL;
p.now=y;
head.next=&p;
}
}
if(id==2){
cin>>x>>y;
node head=sheif[x];
while (head.now!=y&&head.next!=NULL) head=*head.next;
cout<<head.data<<endl;
}
}
system("pause");
return 0;
}
by GeniusRobot @ 2021-04-27 17:56:34
这里啊