2017-后练习

using namespace std;
//平+立
int sq(int temp){
    for(int j=0;j*j<=temp;j++){
        if(j*j==temp)
          return j;
    }
    return 0;
}

int main(){
    int t;
    while(cin>>t){
    int n,count=0;
    for(int i=1;i*i*i<=t;i++){
        if(sq(i*i*i))
        count++;
    }
    cout<<count<<endl;
    }
    return 0;
}

A

#include<iostream>
#include<string.h>
#include<string>
using namespace std;

int judgea(int x){
	for(int i=1;i<=x;i++) {
		if(i*i*i==x)  return 1;
	}
	return 0;
}
int judgeb(int x){
	for(int i=1;i<=x;i++) {
		if(i*i==x)  return 1;
	}
	return 0;
}
int main(){
    int t;cin>>t;int a ,b;
    while(t--){
    	int x;cin>>x;int count=0;
        for(int i=0;i<=x;i++){
		a=judgea(i);
        b=judgeb(i);
        if(a==1&&b==1){
        	count++; 
		}
		}
		cout<<count<<endl;
	}
	return 0;
}

c

#include<iostream>
#include<string.h>
using namespace std;

struct node{
	char data;
	node *lchild,*rchild;
};

node tree[105];
int loc;
node *create(){
   tree[loc].lchild=tree[loc].rchild=NULL;
   return &tree[loc++];
}
void Pre(node *t){
	if(t){
		 Pre(t->lchild);
		 Pre(t->rchild);
		cout<<t->data; 
	}
}
string str1,str2;
node *build(int s1,int e1,int s2,int e2){
	node *ret=create();
	ret->data=str1[s1];
int rootIdx;
    for(int i=s2;i<=e2;i++){
        if(str2[i]==str1[s1]){
            rootIdx=i;
            break;
        }
    }
    if(rootIdx!=s2){
        ret->lchild=build(s1+1,s1+(rootIdx-s2),s2,rootIdx-1);
    }
    if(rootIdx!=e2){
        ret->rchild=build(s1+(rootIdx-s2)+1,e1,rootIdx+1,e2);
    }
    return ret;
}
int main(){	
	while(cin>>str1){
		cin>>str2;
		loc=0;
		int l1=str1.length();
		int l2=str2.length();
		node *t=build(0,l1-1,0,l2-1);
		Pre(t);
		cout<<endl;
	}	
	return 0;
}

b

#include<iostream>
#include<string.h>
#include<cmath>
#include<algorithm>
using namespace std;
int a[100];
void nixu(int l,int r){
	int len=r-l+1;//12345  14325 1 3
	int b[len];
	for(int i=0;i<len;i++){
		b[i]=a[r-i];
	}
	for(int i=l;i<=r;i++){
		a[i]=b[i-l];
	}
}
void ti(int l,int r,int y){
	for(int i=l;i<=r;i++){
		a[i]=y;
	}
}

int main(){
	int m,n,x,y;
	cin>>n>>m;
	int l,r;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}

	while(m--){
		cin>>x;
	if(x==1) {
	   cin>>l>>r;
	   nixu(l-1,r-1);
	   for(int i=0;i<n;i++){
	      cout<<a[i]<<" ";
	}	
	}
	else if(x==3){
	cin>>l>>r;	cin>>y;
		ti(l-1,r-1,y);
         for(int i=0;i<n;i++){
	      cout<<a[i]<<" ";
	}	
	}
	else if(x==4){
	cin>>l>>r;	
	sort(a+l,a+r);
        for(int i=0;i<n;i++){
	      cout<<a[i]<<" ";
	}	
	}

	
}
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值