2017年北京邮电大学计算机考研机试试题及答案

#include<stdio.h>

int main()
{
    int k;
    //判断是否为立方,是否为平方
    int is_pf = 0;
    int is_lf = 0;
    //组数
    scanf("%d",&k);
    while(k--)
    {
        int n;
        scanf("%d",&n);
        int num=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=i;j++)
            {
                if(j*j*j==i)
                {
                    is_lf=1;
                }
                if(j*j==i&&is_lf==1)
                {
                    num++;
                }
            }
            is_lf=0;
            is_pf=0;
        }
        printf("%d\n",num);
    }
     return 0;
}

#include<bits/stdc++.h>
using namespace std;
/*
 9 8
 1 2 3 4 5 6 7 8 9
 1 4 8-->1 2 3 8 7 6 5 4 9
 5 7 9-->5+4+9=18
 2 2 5 3-->1 7 6 5 2 3 8 4 9
 5 5 9-->26
 3 5 8 3-->1 7 6 5 3 3 3 3 9
 4 3 8-->1 7 3 3 3 3 5 6 9
 5 7 9-->5+6+9=20
 */

/*
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
*/

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);

    int a[n+1];
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    while(m--)
    {
        int op;
        scanf("%d",&op);
        int l;
        int r;
        //逆置
        if(op==1)
        {
            scanf("%d%d",&l,&r);
            while(l<=r)
            {
                int temp;
                temp=a[l];
                a[l]=a[r];
                a[r]=temp;
                l++;
                r--;
            }
        }
        if(op==2)
        {
            int len;
            scanf("%d%d%d",&l,&r,&len);
            for(int i=l;i<l+len;i++)
            {
                int temp;
                temp = a[i];
                a[i] = a[i+len];
                a[i+len] = temp;
            }
        }
        if(op==3)
        {
            int x;
            scanf("%d%d%d",&l,&r,&x);
            for(int i=l;i<=r;i++)
            {
                a[i]=x;
            }
        }
        if(op==4)
        {
            scanf("%d%d",&l,&r);
            sort(a+l,a+r+1);
        }
        if(op==5)
        {
            scanf("%d%d",&l,&r);
            int sum=0;
        }
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
/*
426315
623415
*/
typedef struct Bnode{
    struct Bnode *lchild,*rchild;
    int data;
}Bnode,*Bitree;

Bitree PreInCreat(int a[],int b[],int l1,int h1,int l2,int h2)
{
    Bnode* root=(Bnode*)malloc(sizeof(Bnode));
    root->data=a[l1];
    int i;
    for(i=l2;b[i]!=root->data;i++);
    int llen=i-l2;
    int rlen=h2-i;
    if(llen)
        root->lchild=PreInCreat(a,b,l1+1,l1+llen,l2,l2+llen-1);
    else
        root->lchild=NULL;
    if(rlen)
        root->rchild=PreInCreat(a,b,h1-rlen+1,h1,h2-rlen+1,h2);
    else
        root->rchild=NULL;
    return root;
}

void PostOrder(Bitree T)
{
    if(T!=NULL)
    {
        PostOrder(T->lchild);
        PostOrder(T->rchild);
        printf("%d",T->data);
    }
}

int main()
{
    string s1;
    cin>>s1;
    string s2;
    cin>>s2;
    int len = s1.length();
    int a[len+1];
    int b[len+1];
    for(int i=0;i<len;i++)
    {
        a[i+1]=s1[i]-48;
        b[i+1]=s2[i]-48;
    }

    Bitree t = NULL;
    t = PreInCreat(a,b,1,len,1,len);
    PostOrder(t);
    return 0;
}

不会

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值