@一群鶸的鶸 2019-12-03 09:30 回复 ios::sync_with_stdio(false); freopen("transfer.in","r",stdin); freopen("transfer.out","w",stdout); 以上两部在代码中任意删掉一个都能AC,但是在一起就全部WA,为什么啊? #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); freopen("transfer.in","r",stdin); freopen("transfer.out","w",stdout); long long n,ans=0,jsq=0; cin>>n; long long start[n],price[n],sub[n],yh[n][2]; memset(yh,0,sizeof(yh)); memset(start,0,sizeof(start)); memset(price,0,sizeof(price)); memset(sub,0,sizeof(sub)); for(register int i=0;i<n;i++) { cin>>sub[i]>>price[i]>>start[i]; } for(register int i=0;i<n;i++) { if(sub[i]==0) { ans+=price[i]; yh[jsq][0]=start[i]+45; yh[jsq][1]=price[i]; jsq++; } if(sub[i]==1) { int temp=0; for(register int o=0;o<jsq;o++) { if(yh[o][0]>=start[i]&&yh[o][0]!=0&&yh[o][1]>=price[i]) { yh[o][0]=0;yh[o][1]=0; temp=1; break; } } if(temp==0) { ans+=price[i]; } } } cout<<ans; fclose(stdin); fclose(stdout); return 0; }
@一群鶸的鶸 2019-12-03 15:14 回复 举报 回复所有人,今天问了高中的教练 给出的答复是 ios::sync_with_stdio(false); 这句话的意思是关闭scanf和cin的关联,如果下面接着使用scanf和printf进行IO操作 最后fclose是没问题的。 但是如果在代码中用了cout,那么一定不能```cpp fclose(stdout);
ios::sync_with_stdio(false);
freopen("transfer.in","r",stdin); freopen("transfer.out","w",stdout);
以上两部在代码中任意删掉一个都能AC,但是在一起就全部WA,为什么啊?