zoukankan      html  css  js  c++  java
  • SDUST数据结构

    一、判断题:

     

     

     

     

     

     

     

     

     

     

     

    二、选择题:

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    三、编程题:

      7-1 jmu-ds-顺序表区间元素删除 :

    输入样例:

    10
    5 1 9 10 67 12 8 33 6 2
    3 10

    输出样例:

    1 67 12 33 2

    代码:

    #include<stdio.h>
    int main()
    {
        int a[10001];
        int b[10001];//开辟两个比较大的数组 
        int n;
        scanf("%d",&n);
        int i;
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);//将数读入 
        int x, y;
        int j=0;
        scanf("%d %d",&x,&y);
        for(i=0;i<n;i++)//利用区间判断大小,将区间以外的数加入新数组 
        {
            if(a[i]<x||a[i]>y)
            {
                b[j]=a[i];
                j++;
            }
        }    
        printf("%d",b[0]);
        for(i=1;i<j;i++)
        {
            printf(" %d",b[i]);
        }
    } 
    View Code

      

      7-2 两个有序链表序列的合并:

    输入样例:

    1 3 5 -1
    2 4 6 8 10 -1

    输出样例:

    1 2 3 4 5 6 8 10

     代码:

    #include<stdio.h>
    #include<stdlib.h>
    typedef struct LNode//链表 
    {
        int data;
        struct LNode *next;
    }LNode, *LinkList;
    void MergeList_L(LinkList La, LinkList Lb, LinkList Lc)//排序 
    {
        La=La->next;
        Lb=Lb->next;
        while(La!=NULL&&Lb!=NULL)
        {
            if(La->data > Lb->data)
            {
                Lc->next=Lb;
                Lb=Lb->next;
            }
            else
            {
                Lc->next=La;
                La=La->next;
            }
            Lc=Lc->next;
        }
        if(La==NULL&&Lb==NULL) return;
        if(La!=NULL)
            Lc->next=La;
        else 
            Lc->next=Lb;
        return;
    }
    LinkList InitList()// 
    {
        LinkList l;
        l=(LinkList) malloc (sizeof(struct LNode));
        if(!l) return NULL;
        l->next=NULL;
        return l;
    }
    void ReadList_L(LinkList LLL)//读取 
    {
        LinkList temp;
        int data;
        scanf("%d",&data);
        while(data>0)
        {
            temp=(LinkList)malloc(sizeof(struct LNode));
            if(!temp)return;
            temp->data=data;
            temp->next=NULL;
            LLL->next=temp;
            LLL=temp;
            scanf("%d",&data);
        }
        return;
    }
    void PrintList_L(LinkList LL)//打印 
    {
        LL=LL->next;
        if(LL==NULL)
        {
            printf("NULL");
            return;
        }
        while(LL)
        {
            if(LL->next==NULL)
                printf("%d",LL->data);
            else printf("%d ",LL->data);
            LL=LL->next;
        }
    }
    int main()
    {
        LinkList s1,s2,S;
        s1 = InitList();
        s2 = InitList();
        S = InitList();
        ReadList_L(s1);
        ReadList_L(s2); 
        MergeList_L(s1, s2, S);
        PrintList_L(S);
        return 0;
    }
    View Code

      7-3 两个有序链表序列的交集:

    输入样例:

    1 2 5 -1
    2 4 5 8 10 -1

    输出样例:

    2 5

     代码:

    #include<stdio.h>
    int a[10000001],b[100000001];
    int L1=0,L2=0;
    #define true 1
    int main()
    {
        int i=0,j=0,index=-1;
        while(true)//依次读入数组 
        {
            int aa;
            scanf("%d",&aa);
            if(aa==-1)
                break;
            else
                a[L1]=aa,L1++;
        }
        while(true)//依次读入数组 
        {
            int bb;
            scanf("%d",&bb);
            if(bb==-1)
                break;
            else
                b[L2]=bb,L2++;
        }
        while(i<L1 && j<L2)
        {
            if(a[i]==b[j])//出现交集,按规定格式输出 
            {
                if(index==-1)
                {
                    printf("%d",a[i]);
                }
                else
                {
                    printf(" %d",a[i]);
                }
                i++,j++,index++;
            }
            else if(a[i] > b[j])//第一个数组对应的数值大于第二个,让第二个数组的下一个进行比较 
                j++;
            else
                i++;
        }
        if(index==-1)
            printf("NULL
    ");
        else
            printf("
    ");
        return 0;
    }
    View Code

      

      7-4 一元多项式的乘法与加法运算:

    输入样例:

    4 3 4 -5 2  6 1  -2 0
    3 5 20  -7 4  3 1

    输出样例:

    15 24 -25 22 30 21 -10 20 -21 8 35 6 -33 5 14 4 -15 3 18 2 -6 1
    5 20 -4 4 -5 2 9 1 -2 0

    代码:

    #include<iostream>
    #include<cstring>
    using namespace std;
    int t1[1005],t2[1005],s1[2005],s2[2005];//定义全局数组 
    int main(){
        int n1,n2,a,b;
        memset(t1,0,sizeof(t1));
        memset(t2,0,sizeof(t2));
        memset(s1,0,sizeof(s1));
        memset(s2,0,sizeof(s2));//初始化数组 
        cin>>n1;//先输入系数,后输入指数
        for(int i=0;i<n1;i++){
            cin>>a>>b;
            t1[b]=a;
        }
        cin>>n2;
        for(int i=0;i<n2;i++){
            cin>>a>>b;
            t2[b]=a;
        }////指数作为下标,系数作为数组元素
        for(int i=0;i<=1000;i++){
            for(int j=0;j<=1000;j++){
                s1[i+j]+=t1[i]*t2[j];
            }
        }    
        for(int o=0;o<=1000;o++){
            s2[o]+=t1[o]+t2[o];        
        }
        int tag=0;
        for(int i=2000;i>=0;i--)
            if(s1[i]!=0){
                if(tag)
                    cout<<" ";
                tag=1;
                cout<<s1[i]<<" "<<i;
            }//判断个事进行输出 
        if(!tag)cout<<"0 0";
        cout<<endl;
        tag=0;
        for(int i=1000;i>=0;i--)
            if(s2[i]!=0){
                if(tag)
                    cout<<" ";
                tag=1;
                cout<<s2[i]<<" "<<i;
            }//同上 
        if(!tag)cout<<"0 0";
        cout<<endl;
        return 0;
    }
    View Code

      

      7-5 一元多项式求导:

    输入样例:

    3 4 -5 2 6 1 -2 0

    输出样例:

    12 3 -10 1 6 0

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int a, b;
        int s = 0;//用于计算系数和幂的乘积
        cin>>a>>b;
        if(b != 0)
            cout<<(a*b)<<" "<<(b-1);//先计算一组,方便最后一组末尾的消除空格
        else//特殊情况:即多项式为常数的情况
        {
            cout<<"0 0";
            return 0;
        }
        while(scanf("%d %d", &a, &b) != EOF)//输入多组数据
        {
            if(b != 0)
            {
                s = a*b;
                cout<<" "<<s<<" "<<(b-1);//进行求导计算
            }
        }
        return 0;
    }
    View Code

      

      7-6 求链式线性表的倒数第K项 :

    输入样例:

    4 1 2 3 4 5 6 7 8 9 0 -1

    输出样例:

    7        

    代码:

    #include<stdio.h>
    int a[1000001];//第一次提交显示数组越界(段错误) 
    int main()
    {
        
        int look_for;
        scanf("%d",&look_for);//读入下标 
        int index;
        int i = 0;
        while(scanf("%d",&index)>=0)//将大于等于0的数读入 
        {
            a[i]=index;
            i++;
        }
        i--;//循环里面多一次i++,减掉 
        if(i-look_for<0)//判断下标是否符合要求 
        {
            printf("NULL
    ");
        }
        else
        {
            printf("%d
    ",a[i-look_for]);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    羅素悖論和正則公理
    「陶哲軒實分析」 習題 3.4.4
    常微分方程_阿诺尔德 1.1节,问题6 擴張相空間沿時間軸的平移變換將積分曲線變爲積分曲線
    「陶哲軒實分析」 習題 3.5.1
    常微分方程_阿诺尔德 1.1节,问题6 擴張相空間沿時間軸的平移變換將積分曲線變爲積分曲線
    「陶哲軒實分析」 習題 3.4.4
    css3的新属性 新增的颜色 透明度两种渐变定义多张背景图backgroundsize
    使用sessionStorage获取值和设置值
    PAT A1091 Acute Stroke
    杜教筛算法
  • 原文地址:https://www.cnblogs.com/3cH0-Nu1L/p/13977231.html
Copyright © 2011-2022 走看看