提交记录
思路
统计 A B C D 四个字母的出现次数。
for(int i = 0 ; i < 4 ; i++) {
    if(s[i] == 'A') cnta++;
    else if(s[i] == 'B') cntb++;
    else if(s[i] == 'C') cntc++;
    else if(s[i] == 'D') cntd++;
} 根据题目中所描述的内容:
如果面试者在四轮中有一次发挥被评为 D,或者两次发挥被评为 C,就不会通过面试。如果面试者没有一次被评为 D,并且有三个或以上的 A,则会获得 special offer。其余情况会获得普通 offer。
可以写出如下代码
if(cntd || cntc >= 2) {
    cout << "failed" << endl;
}
else if(!cntd && cnta >= 3) {
    cout << "sp offer" << endl;
}
else {
    cout << "offer" << endl;
} 代码
#include<bits/stdc++.h>
using namespace std;
int main() {
    int t, cnta, cntb, cntc, cntd;
    string s;
    cin >> t;
    while(t--) {
        cnta = cntb  = cntc = cntd = 0;
        cin >> s;
        for(int i = 0 ; i < 4 ; i++) {
            if(s[i] == 'A') cnta++;
            else if(s[i] == 'B') cntb++;
            else if(s[i] == 'C') cntc++;
            else if(s[i] == 'D') cntd++;
        }
        if(cntd || cntc >= 2) {
            cout << "failed" << endl;
        }
        else if(!cntd && cnta >= 3) {
            cout << "sp offer" << endl;
        }
        else {
            cout << "offer" << endl;
        }
    }
    return 0;
}
 
京公网安备 11010502036488号