栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1129 Erdos Numbers

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1129 Erdos Numbers

#include<iostream>#include<map>#include<queue>#include<cstdio>#include<cstring>#include<string>using namespace std;struct Editor{    int ID;        int Num;};vector<int>data[10000];    map<string,int> name;    map<string,int>::iterator pos;int author[10000];        string Erdos = "Erdos,P.";void bfs()    {    queue<Editor>Q;    Editor tmp,now;    int i,id,nNum;    memset(author,-1,sizeof(author));    tmp.ID = name[Erdos];    tmp.Num = 0;    Q.push(tmp);    while(!Q.empty())    {        now = Q.front();    Q.pop();        id = now.ID;        nNum = data[id].size();        for(i=0;i<nNum;i++)        { if(author[data[id][i]] == -1) {     author[data[id][i]] = now.Num + 1;       tmp.ID = data[id][i];     tmp.Num = now.Num + 1;     Q.push(tmp);     }        }    }}int main(){    char str[300];    string fullname;    int p,n,len,numAuthor,numPaper,i,j,title;    int paper[300],iCase = 0;    while(scanf("%d%d",&p,&n)!=EOF && p+n)    {        for(i=0;i<10000;i++) data[i].clear();        name.clear();        numAuthor = 0;        while(p--)        { numPaper = 0; int flag = 1; while(1) {     scanf("%s",str);     fullname = str;     scanf("%s",str);    len = strlen(str);     if(str[len-1] == ':' || str[len-1] == '.')        flag = 0;     str[len-1] = '';     fullname += str;     pos = name.find(fullname);     if(pos == name.end())  name[fullname] = numAuthor ++;     paper[numPaper++] = name[fullname];         if(!flag)     {         gets(str);    break;     } } for(i=0;i<numPaper;i++)    {     for(j=0;j<numPaper;j++)     {         if(i!=j)  data[paper[i]].push_back(paper[j]);     } }        }        pos = name.find(Erdos);        if(pos == name.end())    name[Erdos] = numAuthor++;        bfs();        printf("Database #%dn",++iCase);        while(n--)        { scanf("%s",str);    printf("%s",str); fullname = str; scanf("%s",str);    printf(" %s: ",str); fullname +=str; pos = name.find(fullname); if(pos == name.end() || author[name[fullname]]==-1)     printf("infinityn"); else printf("%dn",author[name[fullname]]);        }        printf("n");    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/375560.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号