题目链接:Dashboard - Codeforces Round 933 (Div. 3) - Codeforces
解题思路:
解题思路:
题目大概意思是字符串中最少去掉几个单词可以使字符串变漂亮,其实只要找“map"和”pie“这两个单词数量,注意判断"mappie",这种情况只算一种,所以遇到这种情况就减一,最后输出答案即可
下面是c++代码:
#include<iostream>
using namespace std;
int main()
{int n, m;string s;cin >> n;while (n--) {int sum = 0;cin >> m;cin >> s;if (s.length() < 3) {cout << sum << endl;continue;}for (int i = 0; i < s.length() - 2; i++) {if (s[i] == 'p' && s[i + 1] == 'i' && s[i + 2] == 'e') {sum++;}else if (s[i] == 'm' && s[i + 1] == 'a' && s[i + 2] == 'p') {sum++;}}if (s.length() >= 5) {for (int i = 0; i < s.length() - 4; i++) {if (s[i] == 'm' && s[i + 1] == 'a' && s[i + 2] == 'p' && s[i + 3] == 'i' && s[i + 4] == 'e') {sum--;}}}cout << sum << endl;}return 0;
}