10391

来源:互联网 发布:ov7620数据手册 编辑:程序博客网 时间:2024/05/17 23:17

终于用map做了一道题

感觉如果可以重载 减号的话,用s2 - s1,在查找也挺好的。但我不会重载。。。

#include<cstdio>#include<iostream>#include<map>#include<string>using namespace std;const int maxn = 120000 + 5;map<string ,int > words;int main(){    string str[maxn];    int n = 0;    while(cin >> str[n]){ words[str[n]] = 1; ++n;}    for(int i = 0; i < n; ++i)    {        string str1,str2;        str1.clear();        str2.clear();        for(int j = 0;j < str[i].length(); ++j)        {            str1 += str[i][j];            if(words[str1]==1)            {                str2 = &str[i][j+1];                if(words[str2]==1){cout << str[i] <<endl;break;}            }        }    }    return 0;}


0 0
原创粉丝点击