题解 P7533

· · 题解

这是一道非常简单的字符串统计题。

大致思路

对于每次输入的字符串 s, 挨个判断字符串中的每一个字符是否是 A,K,Q,J 中的一个,如果是就按照题目要求累加分数,反之如果是 X 那就不进行任何操作。

代码如下:

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

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    while (n--)
    {
        string s;
        cin >> s;
        for (int i = 0; i < 13; i++)
        {
            if (s[i] == 'A')
            {
                ans += 4;
            } 
            else if (s[i] == 'K')
            {
                ans += 3;
            }
            else if (s[i] == 'Q')
            {
                ans += 2;
            } 
            else if (s[i] == 'J')
            {
                ans += 1;
            }
        }
    }
    cout << ans;
    return 0;
}