码迷,mamicode.com
首页 > 其他好文 > 详细

HDU GPA

时间:2015-04-22 11:39:20      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:acm   java   

Sample Input
A B C D F
B F F C C A
D C E F
Sample Output
2.00
1.83

Unknown letter grade in input


import java.text.DecimalFormat;
import java.util.Scanner;
public class PracticeVI {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#.00");
String input;
Double sum,value;
Boolean flag;
while(sc.hasNextLine()){
sum = 0.0;value=0.0;
flag = false;
input = sc.nextLine();
String[] chs = input.split(" ");
for(int i=0; i<chs.length; i++){
if("A".equals(chs[i]))
sum = sum + 4;
else if("B".equals(chs[i]))
sum = sum + 3;
else if("C".equals(chs[i]))
sum = sum + 2;
else if("D".equals(chs[i]))
sum = sum + 1;
else if("F".equals(chs[i]))
sum = sum + 0;
else if(" ".equals(chs[i]))
continue;
else{
flag = true;
break;
}
}
if(flag)
System.out.println("Unknown letter grade in input");
else{
value = sum / chs.length;
System.out.println(df.format(value));
}
}
}
}

HDU GPA

标签:acm   java   

原文地址:http://blog.csdn.net/lian_li/article/details/45191691

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!