#25997: c++ cin.tie(0)


leodream251324@gmail.com (Leo Hsu)

學校 : 不指定學校
編號 : 132868
來源 : [140.112.243.234]
最後登入時間 :
2021-07-11 18:03:10
a291. nAnB problem | From: [140.112.243.234] | 發表日期 : 2021-07-10 14:00

如題,我輸入cin.tie(0); cout.tie(0)後有解決TLLE的問題,不過仍然花了0.9秒,想請問如何加速,謝謝

#include<iostream>
using namespace std;

int main(){
int standard[4] = {0};
cin.tie(0);
cout.tie(0);
while(cin>>standard[0]>>standard[1]>>standard[2]>>standard[3]){
int times;
cin>>times;
int ans[4] = {0};
while(times--){
cin>>ans[0]>>ans[1]>>ans[2]>>ans[3];
int A = 0, B = 0;
int A_cond[4] = {0};
int B_cond[10] = {0};
//list all the numbers
for(int i = 0; i<4; i++){
if(ans[i]==standard[i]){
A++;
A_cond[i] = 1;
}
}
for(int i = 0; i<4; i++){
if(A_cond[i]){
continue;
}
for(int j = 0; j<4; j++){
if(A_cond[j]){
continue;
}
if(ans[i]==standard[j]){
if(!B_cond[j]){
B++;
B_cond[j] = 1;
break;
}
}
}
}
cout<<A<<'A'<<B<<'B'<<'\n';
}
}


return 0;
}
 
ZeroJudge Forum