1 条题解

  • 0
    @ 2022-5-22 12:13:06

    练68.3  车牌问题

    解题思路

    市区开头字符固定为ABCDEFGRST。每个车牌取首字符,不在这集合中就计入郊区。

    正确性说明

    依题目给出的对应关系逐项处理,位置与原输入保持明确对应。每一步完成当前项的全部贡献,结束后得到所有位置或字符的目标结果。

    易错点

    只看首字母,数字无需计算。

    复杂度

    n块、长度固定,时间O(n),空间O(1)。

    参考代码(C++11)

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int n;
        cin >> n;
        string urban = "ABCDEFGRST";
        int ans = 0;
        while (n--) {
            string s;
            cin >> s;
            if (urban.find(s[0]) == string::npos)
                ans++;
        }
        cout << ans << "\n";
        return 0;
    }
    
    • 1

    信息

    ID
    444
    时间
    1000ms
    内存
    64MiB
    难度
    进阶
    标签
    递交数
    0
    已通过
    0
    上传者