1 条题解
-
0
C :
#include<stdio.h> #include<string.h> int main() { char a[80]; int i,l,n; double s; while(gets(a)) { l=strlen(a); for(n=s=i=0;i<l;i=i+2) { if(a[i]=='A') s+=4; else if(a[i]=='B') s+=3; else if(a[i]=='C') s+=2; else if(a[i]=='D') s+=1; else if(a[i]!='F') n++; } printf(n?"Unknown\n":"%.2lf\n",s/((l+1)/2)); } return 0; }
C++ :
#include<stdio.h> #include<string.h> int main() { char a[80]; int i,l,n; double s; while(gets(a)) { l=strlen(a); for(n=s=i=0;i<l;i=i+2) { if(a[i]=='A') s+=4; else if(a[i]=='B') s+=3; else if(a[i]=='C') s+=2; else if(a[i]=='D') s+=1; else if(a[i]!='F') n++; } printf(n?"Unknown\n":"%.2lf\n",s/((l+1)/2)); } return 0; }
Pascal :
program p1010; var ch:char; st:string; s:real; i,j,k:longint; y:boolean; begin while not eof do begin readln(st); s:=0; y:=true; while pos(' ',st)<>0 do delete(st,pos(' ',st),1); for i:=1 to length(st) do case st[i] of 'A':s:=s+4; 'B':s:=s+3; 'C':s:=s+2; 'D':s:=s+1; 'F':s:=s+0 else y:=false; end; if y then writeln((s/length(st)):0:2) else writeln('Unknown'); end; end.
Java :
import java.text.DecimalFormat; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { String line = scanner.nextLine(); String[] str = line.split("\\s+"); int length = str.length; double sum = 0; boolean flag = false; for (int i = 0; i < length; i++) { String s = str[i].trim(); if (s.length() == 1) { char ch = s.charAt(0); double n = getScore(ch); if (n == -1) { flag = true; System.out.println("Unknown"); break; } else { sum += (double)n + 0.0001; } } else { // flag = true; // System.out.println("Unknown"); // break; } } if (flag) continue; DecimalFormat df = new DecimalFormat("0.00"); System.out.println(df.format(sum / (double)length)); } } public static double getScore(char ch) { switch (ch) { case 'A': return 4; case 'B': return 3; case 'C': return 2; case 'D': return 1; case 'F': return 0; default: return -1; } } }
Python :
#coding = utf-8 import re import sys f = sys.stdin; #f = open('test.in', 'r'); def GetAns(line): markSet = ['A', 'B', 'C', 'D', 'F',]; hashVal = { 'A':4, 'B':3, 'C':2, 'D':1, 'F':0 }; ave = 0.0; for var in line: if( markSet.count(var) > 0 ): ave += hashVal[var]; else: return 'Unknown'; return ('%.2lf'%(1.0*ave/len(line))); for line in f: line = line.split(' '); line[len(line)-1] = line[len(line)-1][:-1]; print (GetAns(line));
- 1
信息
- ID
- 6208
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者