【九度OJ】1048【模拟】

来源:互联网 发布:c语言谭浩强实验 编辑:程序博客网 时间:2024/05/21 22:29

代码1:

package Test1;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.StreamTokenizer;public class Test20_1048 {public static void main(String [] args) throws IOException{StreamTokenizer st=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));while((st.nextToken())!=StreamTokenizer.TT_EOF){int a=(int)st.nval;st.nextToken();int b=(int)st.nval;st.nextToken();int c=(int)st.nval;int one=a*a-b*b-c*c;int two=b*b-a*a-c*c;int three=c*c-b*b-a*a;if(one==0 || two==0 || three==0)System.out.println("直角三角形");else if(one>0 || two >0 || three>0)System.out.println("钝角三角形");else System.out.println("锐角三角形");}}}
代码2:

package Test1;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.StreamTokenizer;import java.util.Arrays;public class Test21_1048 {/** * by qr jobdu 1048 2014-8-13 * @throws IOException  *//* * 若c²>a²+b²,这是钝角三角形    c²=a²+b²,这是直角三角形    c²<a²+b²,这是锐角三角形 */public static void main(String[] args) throws IOException {StreamTokenizer st=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));int side[]=new int[3];while((st.nextToken())!=StreamTokenizer.TT_EOF){side[0]=(int)st.nval;st.nextToken();side[1]=(int)st.nval;st.nextToken();side[2]=(int)st.nval;Arrays.sort(side);//c^2-b^2-a^2int flag=side[2]*side[2] -side[1]*side[1]-side[0]*side[0];if(flag==0)System.out.println("直角三角形");else if(flag>0)System.out.println("钝角三角形");elseSystem.out.println("锐角三角形");}}}

这两种代码都可以,第二种要排序时间会长一些



0 0
原创粉丝点击