1 条题解
-
0
练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