2012年北邮网研上机

//2012年北邮网研院机试 A
//2018/3/2
//by ben yafang
#include<stdio.h>
#include<string.h>
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		char test;
		getchar();
		scanf("%c",&test);//waiting to count
		getchar();
		char input[1000];		
		scanf("%s",input);
		int count = 0;//initial
		int len = strlen(input);
		for(int i = 0;i < len;i++){//sizeof(input)
			if(input[i] == test){
				count++;	
			}
		}
		printf("%d\n",count);
	}
	return 0;
} 

//2012年北邮网研院机试 B
//2018/3/2
//by ben yafang
//二叉树层次遍历/队列 
#include<stdio.h>
#include<queue>
using namespace std;
struct node {
	int id,depth;//打印节点所在深度 
	node *lchild;//指针节点 
	node *rchild; 
}tree[101];//最多100个节点,下标0不储存节点 
int main(){
	int t;
	scanf("%d",&t);
	int T = t;
	while(t--){//0<t<=10
		int n,m;//n--row  m--node
		scanf("%d %d",&n,&m);
		for(int i = 1;i <= m;i++){//最多存储m个节点,对m个node初始化 
			tree[i].id = i;
			tree[i].depth = 0;
			tree[i].lchild = NULL;
			tree[i].rchild = NULL; 
		} 
		tree[1].depth = 1;
		int a,b;//b is a's father
		for(int i = 0;i < n;i++){
			scanf("%d %d",&a,&b);
			tree[a].depth = tree[b].depth + 1;
			if(tree[b].lchild == NULL) tree[b].lchild = &tree[a];
			else tree[b].rchild = &tree[a];//&tree[a]
		}
		printf("Q%d:\n",T-t);//第几组数据 
		queue<node *> Q;//定义队列 
		Q.push(&tree[1]);//进队 
		int level = 0;//若level与出队节点depth不等,则输出回车,否则空格 
		node *temp;//暂时存储出队节点 
		int flag = 0;
		while(!Q.empty()){
			temp = Q.front();
			Q.pop();
			if(temp->depth == level){//不是当层第一个输出节点 
				printf(" %d",temp->id); 
			}
			else{
				printf("\n%d",temp->id);	
				level++;
			} 
			if(temp->lchild) Q.push(temp->lchild);
			if(temp->rchild) Q.push(temp->rchild);
		}
		printf("\n"); 
		
	}
}

//2012年北邮网研院机试 C 
//2018/3/2
//by ben yafang 
//sscanf(s,"%d.%d",&a,&b);
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
	int t;
	scanf("%d",&t);
	char ip[20];
	char k;
	while(t--){
//		char ip[20];
		scanf("%s",ip);
		int test[4];
		k=0;
		if(sscanf(ip,"%d.%d.%d.%d%c",&test[0],&test[1],&test[2],&test[3],&k)==4){
//			printf("%c",k); 
//			printf("%d,%d,%d,%d",test[0],test[1],test[2],test[3]);
			if(k==0&&test[0] >=0 && test[0] <=255 && test[1] >= 0 && test[1] <= 255 && test[2] >= 0 && test[2] <= 255 && test[3] >= 0 && test[3] <= 255){
				printf("Yes");
			}
			else printf("No");
		} 
		else printf("No");
		if(t!=0)printf("\n");
	}
	return 0;
} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值