码迷,mamicode.com
首页 > 其他好文 > 详细

笔试题:360找镇长的题。

时间:2015-08-12 13:22:12      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:360   选镇长   

技术分享
题目描述:
多个镇里面有n个人在选镇长,在每一个村里面选择一个所有村名(1…n标记)都认识的人,(这个人可以不认识所有人),如果有多个人则同时列出来。
输入描述:
第一行输入的是镇子个数,第二行第一个数是第一个镇子中
的人数,第二个数是关系数,有多少关系数接下来连续输入的就是关系数。
输出描述:
每个镇子按次序输出,先输出预选镇长人数,然后是镇长的罗列。

#include <iostream>
#include <string.h>
using namespace std;

struct Node
{
    int index;
    Node *next;
    Node(int d = int()):index(d),next(NULL){}
};

struct My_Node
{
  Node *adj;
    int count;
    My_Node():adj(NULL),count(0){}
};

int main()
{
    int a,b;
    int n;
    int size;
    My_Node node[1000];
    int k = 0;
    cin>>n;
while(n--)
    {
        cin>>a>>b;
        int c,d;
        int *PeoPle = new int[a];
        memset(PeoPle,0,sizeof(PeoPle));
        size = a;
        while(b--)
        {
                cin>>c>>d;
                if(c!=d)
                {
                    PeoPle[d]++;
                }
        }
        k++;
        for(int i = 1;i<=size;i++)
        {
            if(PeoPle[i]==size-1)
            {
                    node[k-1].count++;
                    Node *s = new Node(i);
                    Node *p = node[k-1].adj;
                    if(p==NULL)
                    {
                        node[k-1].adj = s;
                    }
                    else
                    {
                        while(p->next!=NULL)
                        {
                            p=p->next;
                        }
                        p->next = s;
                }
        }   
     }
    }
    for(int i = 0;i<k;i++)
    {
        Node *p = node[i].adj;
        cout<<node[i].count<<endl;
        if(node[i].count==0)cout<<endl;
        while(p!=NULL)
        {   
            cout<<p->index<<endl;
            p=p->next;
        }
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

笔试题:360找镇长的题。

标签:360   选镇长   

原文地址:http://blog.csdn.net/liuhuiyan_2014/article/details/47442401

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!