PKU 3193 STL

好久没写了 太懒了 太菜了
这个题因为不会写 虽然不难 但是STL我实在知道的太少了 所以贴一下 备忘

#include <iostream>
#include <set>
#include <cstring>

using namespace std;


int main()
{
    int i,j,sum=0;
    int m,n;
    char str[100],word[10000][100];
    set<string>s;
    set<string>::iterator it;

    cin>>m>>n;
    getchar();
    for(i=0;i<m;i++)
    {
        gets(str);
        s.insert(str);
    }

    for(it=s.begin(),i=0;it!=s.end();it++)
        strcpy(word[i++],(*it).c_str());

    int high,low,mid;

    for(i=0;i<n;i++)
    {
        gets(str);
        low=0;high=m-1;
        while(low<high-1)
        {
            mid=(low+high)/2;
            if(strcmp(word[mid],str)<0) low=mid;
            else high=mid;
        }
        for(j=low;j<=high;j++)
        {
            if(strstr(word[j],str)==word[j]) {sum++;break;}
        }

    }

    cout<<sum<<endl;

}


posted on 2008-09-10 21:00 Victordu 阅读(479) 评论(0)  编辑 收藏 引用


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


导航

<2008年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

统计

常用链接

留言簿(5)

随笔档案(46)

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜