跳到正文

题解

P12517 「MSTOI-R1」MST Find

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

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟
题目
P12517

版本

  1. v1当前

P12517「MSTOI-R1」MST Find

题目大意

给定一个长度为 n(n≤100000)n(n≤100000) 的字符串,求其中 m、s、t 分别有多少个。

解题思路

本体只需要遍历字符串判断出现次数即可,值得注意的是,不论大写小写出现都算该字母出现。

AC代码及AC记录

C++
#include <bits/stdc++.h>
using namespace std;
int main(){
	char a[100005];//字符串长度不超过100000。
	cin.getline(a,100000);
	int m=0,s=0,t=0;//记录字母出现次数的变量,记得初始化为0。
	for(int i=0;i<strlen(a);i++){//遍历字符串
		if(a[i]=='m'||a[i]=='M')//寻找字母m。
			m++;
		else if(a[i]=='s'||a[i]=='S')//寻找字母s。
			s++;
		else if(a[i]=='t'||a[i]=='T')//寻找字母t。
			t++;
	}
	cout<<m<<' '<<s<<' '<<t;//按题目要求输出。
	return 0;
}

AC记录\

原文