相关知识

  1. 常见数据结构的求和方式都有哪些? 循环遍历。accumulate(begin_iterator, end_iterator, initial_value, binary_operation):这个函数配合lambda表达式和三目运算符「?:」非常好用。

第一轮

最后一版(AC)

#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main() {
    string s;
    getline(cin, s);

    vector<int> count(26, 0);
    for (char c : s) {
        if (c - 'A' >= 0 && c - 'Z' <= 0) {
            count[c - 'A']++;
        }
    }

    int sum = accumulate(count.begin(), count.end(), 0);

    cout << sum;
}
// 64 位输出请用 printf("%lld")

  1. 这里用的是笨办法,先声明了一个vector来统计每个大写字母的出现次数,然后求和。

第二轮

第一版

#include <cctype>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main() {
    string s;
    getline(cin, s);

    int count = 0;
    for (char c : s) {
        if(isupper(c)) count++;
    }

    cout << count << endl;
    
    return 0;
}
// 64 位输出请用 printf("%lld")