算法训练 斜率计算
时间限制:1.0s 内存限制:512.0MB
输入两个点的坐标,即p1 = (x1, y1)和p2=(x2, y2),求过这两个点的直线的斜率。如果斜率为无穷大输出“INF”。
样例输入
1 2
2 4
2 4
样例输出
2
样例输入
1 2
1 4
1 4
样例输出
INF
样例输入
1 2
3 2
3 2
样例输出
0
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); int a[]=new int[4]; for(int i=0;i<4;i++){ a[i]=sc.nextInt(); } if(a[2]-a[0]==0) System.out.println("INF"); else System.out.println((a[3]-a[1])/(a[2]-a[0])); } }