noj06LOCATE操作

在这里插入图片描述
在这里插入图片描述
Locete操作

#include <stdio.h>
#include <stdlib.h>

typedef struct Node
{
         struct Node *pre;
         char data;
         struct Node *next;
         int freq;
}Node,*ListNode;

void CreatList(ListNode name,int n)
{
    ListNode temp=name;
    for(int i=0;i<n;i++)
    {
        ListNode p=(ListNode)malloc(sizeof(Node));
        p->data=0;
        p->freq=0;
        p->pre=temp;
        temp->next=p;
        temp=temp->next;
    }
    temp->next=name;
}

void paixu(ListNode name,int n)
{
    ListNode p=name->next;
    ListNode q=p->next;
    char k;
    int f;
    for(int i=0;i<n-1;i++)
    {
        p=name->next;
        q=p->next;
        for(int j=0;j<n-i-1;j++)
        {
            if(p->freq < q->freq)
            {
               k=p->data;
               p->data=q->data;
               q->data=k;
               f=p->freq;
               p->freq=q->freq;
               q->freq=f;
            }
            p=p->next;
            q=q->next;
        }
    }
}

void PrintList(ListNode name)
{
    ListNode p =name->next;
    while(p!=name)
    {
        printf("%c ",p->data);
        p=p->next;
    }
}

void fangwen(ListNode name,char a)
{
    ListNode p=name->next;
    while(p!=name)
    {
        if(p->data == a)
        {
            p->freq++;
            break;
        }
        else
        {
            p=p->next;
        }
    }
}

int main()
{
    int m,n;
    scanf("%d %d",&m,&n);
    ListNode a=(ListNode)malloc(sizeof(Node));
    CreatList(a,m);
    ListNode temp=a->next;
    int i=0;
    while(1)
    {
        char c=getchar();
        if(c!=' '&&c!='\n')
        {
            temp->data=c;
            temp=temp->next;
            i++;
            if(i==m)
            {
                break;
            }
        }
    }
    ListNode b=(ListNode)malloc(sizeof(Node));
    CreatList(b,n);
    ListNode tempb=b->next;
   // char nouse2=getchar();
    int j=0;
    while(1)
    {
        char c=getchar();
        if(c!=' '&&c!='\n')
        {
            tempb->data=c;
            tempb=tempb->next;
            j++;
            if(j==n)
            {
                break;
            }
        }
    }
    ListNode bb=b->next;
    while(bb!=b)
    {
        fangwen(a,bb->data);
        bb=bb->next;
    }
    paixu(a,m);
    PrintList(a);
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值