情书std
  • 板块P2264 情书
  • 楼主lin_toto葉月ゆら
  • 当前回复27
  • 已保存回复27
  • 发布时间2014/11/3 18:42
  • 上次更新2024/4/5 16:10:04
查看原帖
情书std
256
lin_toto葉月ゆら楼主2014/11/3 18:42

看大家都被卡了好久。。

[codec]

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
using namespace std;
string replace_all(string str,const string old_value,const string new_value)   
{   
    for(string::size_type pos(0); pos!=string::npos; pos+=new_value.length()) {    
        if((pos=str.find(old_value, pos))!=string::npos) 
            str.replace(pos,old_value.length(),new_value);   
        else break;   
    }   
    return str;   
}  
int main() {
    vector<string> matches;
    int n;
    cin >> n;
    for(int i=0;i<n;i++) {
        string t;
        cin >> t;
        transform(t.begin(), t.end(), t.begin(), ::tolower);
        matches.push_back(t);
    }
    int g = 0;
    string text;
    cin.ignore();
    getline(cin, text);
    transform(text.begin(), text.end(), text.begin(), ::tolower);
    text = replace_all(text, ",", " ");
    text = replace_all(text, ".", " . ");
    text = " " + text + " ";
    vector<set<string> > sept;
    set<string> a;
    for(int i=0;i<text.length();i++) {
        while(text[i] == ' ' && i < text.length()) i++;
        if(i==text.length()) break;
        string t = "";
        while(text[i] != ' ') {
            t += text[i];
            i++; 
        } 
        if(t != ".") {
            if(t != "") a.insert(t);
        } else {
            sept.push_back(a);
            a = set<string>();
        }
    }
    for(vector<set<string> >::iterator i = sept.begin(); i < sept.end(); i++) {
        for(vector<string>::iterator j = matches.begin(); j < matches.end(); j++) {
            if((*i).find(*j) != (*i).end()) {
                g++;
            }
        }
    }
    cout << g << endl;
    return 0;
}
[/codec]
2014/11/3 18:42
加载中...