在我的電腦上跑出來都與正確答案一樣,但送出去跑出來的結果竟然不一樣??
而且利用 測試執行,陣列row裡面的值還會自己改變..........
測資分別是
1 5 2 4
------------
4 2 5 1
------------
4 3 5 2
---------
5 1 2 4
---------
2 4 5 1
#include<iostream>
using namespace std;
int main() {
int row[2],col[2];
int arr[2][2];
bool weight[4];
int no,t1,t2;
cin>>row[0]>>row[1]>>col[0]>>col[1];
int i,j,k;
for(i=0; i<2; i++) {
for(j=0; j<2; j++) {
memset(weight,false,sizeof weight);
arr[i][j]=0;
arr[i][(-1)*j+1] = row[i]; //same row
arr[(-1)*i+1][j] = col[j]; //same col
weight[row[i]]=true;
weight[col[j]]=true;
t1 = row[(-1)*i+1] - arr[(-1)*i+1][j];
t2 = col[(-1)*j+1] - arr[i][(-1)*j+1];
no = 0;
if(t1>0) {
weight[t1]=true;
}
for(k=1; k<4; k++) {
if(!(weight[k])) {
no = 1;
}
}
if(t1==t2 && no==0) {
arr[(-1)*i+1][(-1)*j+1] = t1;
cout<<arr[0][0]<<" "<<arr[0][1]<<endl;
cout<<arr[1][0]<<" "<<arr[1][1]<<endl;
return 0;
}
}
}
cout<< "No solutions.\n";
return 0;
}