//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;
}