Codeforces Round #188 (Div. 2) Strings of Power

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    string text;
    cin >> text;
    vector<int> heavyPos,metalPos;
    size_t pos = 0;
    while((pos = text.find("heavy",pos)) != string::npos) heavyPos.push_back(pos++);
    pos = 0;
    while((pos = text.find("metal",pos)) != string::npos) metalPos.push_back(pos++);
    long long cnt = 0;
    int j = 0;
    for(int i = 0 ; i < heavyPos.size(); i ++ ){
        for(; j < metalPos.size(); j ++ ){
            if(heavyPos[i] < metalPos[j]){
                cnt +=metalPos.size()-j;
                break;
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}

  

原文地址:https://www.cnblogs.com/xiongqiangcs/p/3137310.html