From 144ec95549681d05490517e5c6a9f53092ab93dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=9B=E9=AA=8F=E6=B4=8B?= <836157478@qq.com> Date: Thu, 3 Aug 2023 05:49:25 +0000 Subject: [PATCH] =?UTF-8?q?update=20problems/0007.=E5=B9=B3=E5=9D=87?= =?UTF-8?q?=E7=BB=A9=E7=82=B9.md.=20=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=8F=A6?= =?UTF-8?q?=E4=B8=80=E7=A7=8DJava=E7=89=88=E6=80=9D=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 盛骏洋 <836157478@qq.com> --- ...63\345\235\207\347\273\251\347\202\271.md" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git "a/problems/0007.\345\271\263\345\235\207\347\273\251\347\202\271.md" "b/problems/0007.\345\271\263\345\235\207\347\273\251\347\202\271.md" index d00a51d..ad936df 100644 --- "a/problems/0007.\345\271\263\345\235\207\347\273\251\347\202\271.md" +++ "b/problems/0007.\345\271\263\345\235\207\347\273\251\347\202\271.md" @@ -83,6 +83,44 @@ public class Main { } } ``` +### Java思路2 +```Java +import java.util.Scanner; +import java.text.DecimalFormat; + +public class Main { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + while(in.hasNextLine()){ + int sum = 0; + boolean flag = true; + String s = in.nextLine(); + for (int i = 0; i < s.length(); i++) { + switch(s.charAt(i)){ + case ' ': + case 'F': break; + case 'A': sum+=4; break; + case 'B': sum+=3; break; + case 'C': sum+=2; break; + case 'D': sum+=1; break; + default : { + flag=false; + break; + } + } + if (!flag) break; //提前结束遍历当前行 + } + if (!flag) { + System.out.println("Unknown"); + } else { + DecimalFormat df = new DecimalFormat("0.00"); + int num = (s.length() + 1) / 2; //去掉空格 + System.out.println(df.format(1.0 * sum / num)); + } + } + } +} +``` ## python -- Gitee