2 return2/13

#include<bits/stdc++.h>
#include<math.h>
using namespace std;

int main(){
    string s;
    
    while(getline(cin,s)){
        float cnt = 0;
        int cc = 0;
        int flag = 1;      
            for(int i=0; i < s.size(); i++){
                if(s[i] == 'A') cnt += 4,cc++;
                else if(s[i] == 'B') cnt += 3,cc++;
                else if(s[i] == 'C') cnt += 2,cc++;
                else if(s[i] == 'D') cnt += 1,cc++;
                else if(s[i] == 'F') cnt += 0,cc++;
                else if(s[i] == ' ') continue;
                else {
                    flag = 0;
                    cout << "Unknown" <<endl;
                    break;
                } 
            }
        if(flag)
        printf("%.2f\n", cnt/cc);
    } 
    return 0;
}

注意:

  • 用标记flag时候,默认1是‘正确值’,例如:

if(flag) cout<<"Yes"<<endl;

这里的flag是指的1

  • string是个数组
  • 非特殊的输出统一放在最后进行。
  • 读入字符串时候注意空格,特殊处理一下 ‘ ’ 。

 

posted @ 2024-02-06 11:14  Yoloerr  阅读(12)  评论(0)    收藏  举报