用java刷oj时碰到的一个问题

追风筝的少年 2016-04-10 05:39:43
题目:
Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The only line contains four integers ScoreA, ScoreB, ScoreC, and ScoreD - the four problems' score of the examinee.(0 <= ScoreA <= 20, 0 <= ScoreB, ScoreC <= 25, 0 <= ScoreD <= 30)

Output

For each test case, if the examinee gets 80 points or above in total, output "Yes", else output "No".

Sample Input

4
0 0 5 30
20 25 20 0
20 25 20 15
20 25 25 30
Sample Output

No
No
Yes
Yes
很简单的一个题目,我的java版代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int row=in.nextInt();
int sum,tmp;
for(int i=0;i<row;i++){
sum=0;
for(int j=0;j<4;j++){
tmp=in.nextInt();
sum+=tmp;
}
if(sum>=80)
System.out.println("Yes");
else
System.out.println("No");
}
}
}
c语言版代码:
#include <stdio.h>
int main(){
int row;
scanf("%d",&row);
int sum,tmp;
for(int i=0;i<row;i++){
sum=0;
for(int j=0;j<4;j++){
scanf("%d",&tmp);
sum+=tmp;
}
if(sum>=80)
printf("Yes\n");
else printf("No\n");
}
}
java版的一直提示超时,后来用c语言写了下,立刻就过了,这是什么情况?是代码写错了,还是java效率差那么多?
...全文
192 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
huntor 2016-04-11
  • 打赏
  • 举报
回复
代码没有问题
追风筝的少年 2016-04-11
  • 打赏
  • 举报
回复
引用 1 楼 huntor 的回复:
代码没有问题
我也觉得没问题,题目限时2s,oj一直提示我超时
huntor 2016-04-11
  • 打赏
  • 举报
回复
手动输入的慢,从文件读应该很快

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧