一个大的含有50M个URL的记录,一个小的含有500个URL的记录,找出两个记录里相同的URL。

#include <iostream>
#include <fstream>
#include <string>
#include <hash_set>
using namespace std;
using namespace stdext;

int main()
{
    hash_set<string> hs;
    hash_set<string>::iterator it;

    ofstream out1("file1.txt");
    ofstream out2("file2.txt");
    out1<<"www.baidu.com"<<endl;
    out1<<"www.google.com"<<endl;
    out1<<"www.sina.com"<<endl;

    out2<<"www.baidu.com"<<endl;
    out2<<"www.yahoo.com"<<endl;
    
    ifstream in1("file1.txt");
    ifstream in2("file2.txt");
    string str1;
    string str2;
    while(getline(in2,str2))
    {
        hs.insert(str2);
    }
    while(getline(in1,str1))
    {
        if((it = hs.find(str1)) != hs.end ())
        {
            cout<<"find: "<<str1<<endl;
        }
    }
    system("pause");
    return 0;
}

posted on 2012-08-30 14:53 三少_爷 阅读(187) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年3月>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456

导航

统计

常用链接

留言簿

随笔分类

随笔档案

My Website

搜索

最新评论

阅读排行榜

评论排行榜