跳到正文

题解

题解:P12517 「MSTOI-R1」MST Find

SXY83296647约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年5月14日
篇幅
约 1 分钟
获赞
1
题目
P12517

版本

  1. v1当前

题目传送门

首先来看题目,题目要求是分别输出输入的字符串中 M,S 和 T 的个数。我们就可以通过枚举字符串中的各个字符来计算求和,在此给出以下代码。

AC Code

C++
#include <iostream>
#include <cctype>
using namespace std;
int main()
{
    string a;
    getline(cin,a);//注意空格也是字符串的内容,需整行读入
    int m = 0, s = 0, t = 0;
    for (int i = 0;i < a.length();i++) {
        char lower = tolower(a[i]);//使用cctype的tolower()函数,将字符转换为小写形态,方便判断
        if (lower == 'm') m++;
        else if (lower == 's') s++;
        else if (lower == 't') t++;
    }
    cout << m << " " << s << " " << t << endl;
    return 0;
}
原文