佛山设计网站,电脑编程学校哪家好,易站网站建设,大型门户网站核心技术题目描述 众人皆知#xff0c;在编程领域中#xff0c;C是一门非常重要的语言#xff0c;不仅仅因为其强大的功能#xff0c;还因为它是很多其他面向对象语言的祖先和典范。不过这世上几乎没什么东 西是完美的#xff0c;C也不例外#xff0c;多继承结构在带来强大功能的… 题目描述
众人皆知在编程领域中C是一门非常重要的语言不仅仅因为其强大的功能还因为它是很多其他面向对象语言的祖先和典范。不过这世上几乎没什么东 西是完美的C也不例外多继承结构在带来强大功能的同时也给软件设计和维护带来了很多困难。为此在java语言中只允许单继承结构并采用接口 来模拟多继承。KK最近获得了一份java编写的迷你游戏的源代码他对这份代码非常感兴趣。这份java代码是由n个类组成的本题不考虑接口n个类分别用数字1..n表示。现在给你n个类之间的关系有q次询问每次询问某一个有多少个直接继承的子类。输入子类的个数和标号标号按照字典序大小输出。 输入
首先输入一个整数T表示数据的组数。每组数据格式如下。 第一行包含两个整数n,m表示该份代码中的n个类和m个单继承关系(1mn10^5) 输出
对于每组输入。输出询问类的子类的数量和编号。示例输入 1
10 9
2 1
3 2
4 3
5 3
6 3
7 3
8 3
9 3
10 5
10
7
6
3
7
1
2
8
1
2
5 示例输出 0
0
6
4 5 6 7 8 9
0
1
2
1
3
0
1
2
1
3
1
10#includestdio.h
#includestring.h
#includestdlib.h
#define max 100000
typedef struct node
{int data;node *next;
}node,*Bnode;
void Insert(Bnode head,int x)//有序的邻接表插入函数...头指针的数据域代表后面共有多少个元素对这些元素进行数组存储
{Bnode tail,p,q;//p是q的前驱节点 tail是要插入的节点tailnew node;tail-datax;tail-nextNULL;if(headNULL){headnew node;head-nexttail;// tail-nextNULL;head-data1;//元素个数为1}else{head-data;//链的数据个数phead;qhead-next;while(q){if(q-datax){p-nexttail;tail-nextq;break;//从小到大排序 遇到大的就插入 然后一定要跳出while}pp-next;qq-next;}if(qNULL) //没找到比x大的 所以把x放在最后{p-nexttail;//tail-nextNULL;}}
}
int main()
{int i,t,n,m,a,b;scanf(%d,t);Bnode head[max],tail;while(t--){scanf(%d%d,n,m);for(i1;in;i)head[i]NULL;//初始化for(i0;im;i){scanf(%d%d,a,b);Insert(head[b],a);//将a的数据插入到b的节点中}int q;scanf(%d,q);for(i0;iq;i){int key;scanf(%d,key);if(head[key]NULL)//key值元素个数为空printf(0\n);else{printf(%d\n,head[key]-data);//key值元素的总个数tailhead[key]-next;while(tail){printf(%d,tail-data);if(tail-next!NULL)printf( );tailtail-next;}printf(\n);}}}
}#include iostream
#includecstring
#includevector
#includealgorithm
#includecstdio
using namespace std;
const int Maxn100001;
vectorintG[Maxn];
int t,m,n,q;
int main()
{
cint;
while(t--)
{
cinnm;
int i;
for(i1;in;i)
G[i].clear();
while(m--)
{
int u,v;
cinuv;
G[v].push_back(u);
}
cinq;
while(q--)
{
int num;
cinnum;
int lG[num].size();
if(l0)
cout0\n;
else
{
coutlendl;
sort(G[num].begin(),G[num].end());
vectorint::iterator it;
for(itG[num].begin();itG[num].end();it)
printf(%d ,*it);
coutendl;
//printf(%d\n,G[num][G[num].size()-1]);
}
}
}
//cout Hello world! endl;
return 0;
}