北邮2017年计算机机试

ProblemA 求special数

题目描述(非完整版)

代码

#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		int n;
		scanf("%d",&n);
		int ans=0;
		for(int i=1;i*i*i<=n;i++){
			int tp=i*i*i;
			int ts=(int)sqrt(tp);
			if(ts*ts==tp){
				ans++;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
} 

ProblemB 字符串操作

题目描述(非完整版)

代码

#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
const int MAXV=1000;
int n,m;
int a[MAXV];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
	}
	while(m--){
		int t,l,r;
		scanf("%d%d%d",&t,&l,&r);
		if(t==1){
			for(int i=l,j=r;i<j;i++,j--){
				swap(a[i],a[j]);
			}
		}else if(t==2){
			int len;
			scanf("%d",&len);
			for(int i=0;i<len;i++){
				swap(a[l+i],a[r+i]);
			}
		}else if(t==3){
			int x;
			scanf("%d",&x);
			for(int i=l;i<=r;i++){
				a[i]=x;
			}
		}else if(t==4){
			sort(a+l,a+r+1);
		}else if(t==5){
			int ans=0;
			for(int i=l;i<=r;i++){
				ans+=a[i];
			}
			printf("%d\n",ans);
		}
	}
	return 0;
}
/*9 8
1 2 3 4 5 6 7 8 9
1 4 8
5 7 9
2 2 5 3
5 5 9
3 5 8 3
4 3 8
5 7 9
5 1 9*/ 

ProblemC 二叉树

题目描述 (非完整版)

代码

#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
struct TreeNode{
	TreeNode* lc;
	TreeNode* rc;
	char data;
	TreeNode(char c){
		data=c;
		lc=NULL;
		rc=NULL;
	}
};
TreeNode* getTree(string pr,string in){
	if(pr.length()==0) return NULL;
	char rc=pr[0];
	int len=pr.length();
	TreeNode* root=new TreeNode(rc);
	int index=in.find(rc);
	string lin=in.substr(0,index);
	string rin=in.substr(index+1);
	string lpr=pr.substr(1,lin.length());
	string rpr=pr.substr(1+lin.length());
	root->lc=getTree(lpr,lin);
	root->rc=getTree(rpr,rin);
	return root;
}
void postOrder(TreeNode* root){
	if(root==NULL) return;
	postOrder(root->lc);
	postOrder(root->rc);
	printf("%c",root->data);
}
int main(){
	char buf1[100],buf2[100];
	scanf("%s%s",buf1,buf2);
	string pr(buf1);
	string in(buf2);
	TreeNode* root=getTree(pr,in);
	postOrder(root);
	return 0;
} 

ProblemD

我只有这样一份题,我没看懂那个样例里哪有s和8,可能是我瞎吧,我找资源能力也差,没有从网上找到完整的题目,也没有评测系统,这题放弃了。

注:上面的题只是通过了自己的一些测试数据,没有oj来评测不敢保证完全正确,可参考思路,有错误欢迎指出。

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值