程式碼如下
#include<iostream>
using namespace std;
int main(){
int T;
int a1,a2,a3,a4;
cin>>T;
for(int t=0;t<T;t++){
cin>>a1>>a2>>a3>>a4;
if((a1+a3)/2==a2&&(a2+a4)/2==a3){
cout<<a1<<" "<<a2<<" "<<a3<<" "<<a4<<" "<<(2*a4-a3)<<endl;
}
if((a1*a3)/a2==a2&&(a2*a4)/a3==a3){
cout<<a1<<" "<<a2<<" "<<a3<<" "<<a4<<" "<<(a4*a4/a3)<<endl;
}
}
return 0;
}
程式碼如下
#include
using namespace std;
int main(){
int T;
int a1,a2,a3,a4;
cin>>T;
for(int t=0;t<T;t++){
cin>>a1>>a2>>a3>>a4;
if((a1+a3)/2==a2&&(a2+a4)/2==a3){
cout<<a1<<" "<<a2<<" "<<a3<<" "<<a4<<" "<<(2*a4-a3)<<endl;
}
if((a1*a3)/a2==a2&&(a2*a4)/a3==a3){
cout<<a1<<" "<<a2<<" "<<a3<<" "<<a4<<" "<<(a4*a4/a3)<<endl;
}
}
return 0;
}
你確定不會有測資會同時滿足兩個if 嗎?
試試看 1 1 1 1 , 結果很明顯是判斷式的問題
程式碼如下
#include
using namespace std;
int main(){
int T;
int a1,a2,a3,a4;
cin>>T;
for(int t=0;t<T;t++){
cin>>a1>>a2>>a3>>a4;
if((a1+a3)/2==a2&&(a2+a4)/2==a3){
cout<<a1<<" "<<a2<<" "<<a3<<" "<<a4<<" "<<(2*a4-a3)<<endl;
}
if((a1*a3)/a2==a2&&(a2*a4)/a3==a3){
cout<<a1<<" "<<a2<<" "<<a3<<" "<<a4<<" "<<(a4*a4/a3)<<endl;
}
}
return 0;
}
你確定不會有測資會同時滿足兩個if 嗎?
試試看 1 1 1 1 , 結果很明顯是判斷式的問題
所以是被上個測資影響,謝謝