2016年1月15日 星期五

d623: 反方陣

內容 :
11
輸入說明 : 
輸入有兩行每行有2個數字代表2階方陣
輸入4個0表示結束
輸出說明 : 
輸出此方陣的反方陣
若此方陣無反方陣則輸出cheat!
範例輸入 : help
1 2
3 4
1 1
1 1
0 0
0 0
範例輸出:
-2.00000 1.00000
1.50000 -0.50000
cheat!
提示 : 
標籤:
出處: 
leopan0922 (管理:leopan0922)


import java.util.NoSuchElementException;
import java.util.Scanner;

public class d623 {

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
try{
while(sc.hasNext()){
double a=sc.nextDouble(),b=sc.nextDouble(),c=sc.nextDouble(),d=sc.nextDouble();
double temp=1/(a*d-b*c);
if(a==0 && b==0 && c==0 && d==0)
break;
else if(temp==0)
System.out.println("cheat!");
else
System.out.printf("%.5f %.5f\n%.5f %.5f\n",d*temp,-b*temp,-c*temp,a*temp);
}
}catch(NoSuchElementException ex){}

}

}

沒有留言:

張貼留言