美团第一题编程,调手表角度

第一道编程题,本地样例测试通过,粘上去后调试死活都是通过率0%,求大神指点
附代码:
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int i=0;
while(sc.hasNextLine()){
i++;
sc.nextLine();
int a=Integer.parseInt(sc.nextLine());
int b=Integer.parseInt(sc.nextLine());
int result=calculate(a,b);
System.out.println("Output Sample "+i);
System.out.println(result);
}
sc.close();
}

public static int calculate(int a, int b) {
// TODO Auto-generated method stub
if(a>=b){
int result1=360-a+b;
int result2=a-b;
return compare(result1,result2);
}
else{
int result1=b-a;
int result2=360-b+a;
return compare(result1,result2);
}
}

public static int compare(int result1, int result2) {
// TODO Auto-generated method stub
if(result1<=result2)
return result1;
else
return -result2;
}

}


全部评论
你们写的好烦,(X1-x2+360)%360和(x2-X11+360)%360比较,就可以了
点赞 回复 分享
发布于 2017-09-01 00:43
要有输出cout,不能是return
点赞 回复 分享
发布于 2017-09-02 11:53
因为你写了output sample……直接输出结果就可以的……那个是例子啊……
点赞 回复 分享
发布于 2017-09-01 11:23
因为你写了output sample……直接输出结婚就可以的……那个是例子啊……
点赞 回复 分享
发布于 2017-09-01 11:12
-
点赞 回复 分享
发布于 2017-09-01 09:12
package com.fqyuan.meituan; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int x1 = scanner.nextInt(); int x2 = scanner.nextInt(); System.out.println(how2Rotate(x1, x2)); } public static String passTest(int[] input) { String result = "No"; int sum = input[0]; int maxVal = input[0]; for (int i = 1; i < input.length; i++) { sum += input[i]; if (input[i] > maxVal) maxVal = input[i]; } if (maxVal * 2 > sum) result = "No"; else result = "YES"; return result; } public static int how2Rotate(int x1, int x2) { int result = 0; if (x1 > x2) { if (x1 - x2 > 180) result = 360 - x1 + x2; else result = -1 * (x1 - x2); } else { if (x2 - x1 > 180) result = -1 * (360 - x2 + x1); else result = x2 - x1; } return result; } }
点赞 回复 分享
发布于 2017-08-31 22:00

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务