2010北邮网研复试上机

//牛客网 查找 
//2018/3/7
//by ben yafang
//done
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
char input[101];
char order[101];
void Convert(char input[],int left,int right){
	char temp;
	while(left<right){
		temp = input[left];
		input[left] = input[right];
		input[right] = temp;
		left++;
		right--;
	}
	return;
}
int main(){
	char input[101];
	scanf("%s",input);
	int n;
	scanf("%d",&n);//命令数 
	char result[n][101];
	int t = n;
	while(n--){
		scanf("%s",order);
		int i = order[1]-'0';
		int len = order[2]-'0';
		int left = i;
		int right = i+len-1;
		if(order[0] == '0'){
			Convert(input,left,right);
			strcpy(result[n],input);
		} 
		else if(order[0] == '1'){//3--
			int index = 3;
			while(left <= right){
				input[left] = order[index];
				index++;
				left++;
			}
			strcpy(result[n],input);
		} 
	}
	while(t--){
		printf("%s\n",result[t]);
	}
} 
//牛客网 打牌 
//2018/3/7
//by ben yafang 
//done
#include<stdio.h>
#include<string.h>
int main(){
	char a[101];
	char b[101];
	scanf("%s",a);
	scanf("%s",b);
	int i;
	int flag = 0;//1--yes 0--no
	int count = 0;
	char temp; 
	if(strlen(b) >= 1 && strlen(b) < 5){
		for(i = 0;i < strlen(a);i++){
			if(a[i] > b[0] && count == 0){
				count++;
				temp = a[i];
			}
			else if(a[i] == temp && count > 0 && count < strlen(b))count++;
			else if(a[i] != temp && count > 0 && count < strlen(b)){
				count = 1;
				temp = a[i];
			}
			if(count == strlen(b)){
				flag = 1;
				printf("YES\n");
				break;
			}
		} 
		if(flag == 0)printf("NO\n");
	}
	else if(strlen(b) == 5){
		for(i = 0;i < strlen(a);i++){
			if(a[i] > b[0] && count == 0){
				temp = a[i] - b[0];
				count++;
			}
			else if(count > 0 && count < 5 && a[i] == (temp + b[count])){
				count++;
			}
			else if(count > 0 && count < 5 && a[i] != a[i-1] && a[i] != (temp + b[count])){
				count = 0;
			}
			if(count == 5){
				flag = 1;
				printf("YES\n");
				break;
			} 
		}
		if(flag == 0)printf("NO\n");
	}
	
	return 0;
}


//牛客网 查找树 
//2018/3/7
//by ben yafang 
//done
#include<stdio.h>
struct node{
	int value,height;
	node *lchild;
	node *rchild;
}tree[1001]; 
int main(){
	int n;
	scanf("%d",&n);
	int i;
	int x;
	scanf("%d",&x);
	tree[1].value = x;
	tree[1].height = 1;
	tree[1].lchild = tree[1].rchild = NULL;
	for(i = 2;i <= n;i++){
		scanf("%d",&x);
		tree[i].value = x;
		tree[i].height = tree[i/2].height + 1;
		tree[i].lchild = tree[i].rchild = NULL;
		if(tree[i/2].lchild == NULL){
			tree[i/2].lchild = &tree[i];
		}
		else if(tree[i/2].lchild == NULL){
			tree[i/2].rchild = &tree[i];
		}
	}
	int depth;
	scanf("%d",&depth);
	int count = 0;
	for(i = 1;i <= n;i++){
		if(tree[i].height == depth){
			if(count == 0){
				printf("%d",tree[i].value);
				count++;
			}
			else{
				printf(" %d",tree[i].value);
			}
		}
		if(i == n && tree[i].height < depth)printf("EMPTY");
	}
}
//牛客网 输出第k小的数
//2018/3/7
//by ben yafang 
//done
#include<stdio.h>
#include<algorithm>
using namespace std; 
int main(){
    int n;
    scanf("%d",&n);
    int input[n];
    int k;
    for(int i = 0;i < n;i++){
        scanf("%d",&input[i]);
    }
    scanf("%d",&k);
    sort(input,input+n);//1 4 2 3 2 5
    int count = 1;//1 2 2 3 4 5
    for(int i = 0;i < n;i++){//1
    	if(count < k && input[i] != input[i+1])count++;
    	else if(count == k){
    		printf("%d",input[i]);
    		break;
		}
	}
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值