• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
james1207

博客园    首页    新随笔    联系   管理    订阅  订阅

wust 1061 链表的合并

怒刷存在感!

~从此wustoj踏上ty博客这样高端霸气上档次的地方啊啦啦~


只是顺便看了下保研复试题,原来觉得链表好讨厌,现在数据结构学的没办法了,写了个大概是标准的链表合并的写法吧。。。



 

#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#define inf 0x3f3f3f3f
using namespace std;

struct node
{
    int num;
    int score;
}a[1000],b[1000],c[2000];

bool cmp(node x,node y)
{
    return x.num<y.num;
}

int main()
{
    int n,m,k,i,j;
    while(~scanf("%d%d",&n,&m))
    {
        for(i=0;i<n;i++)
            scanf("%d%d",&a[i].num,&a[i].score);
        for(i=0;i<m;i++)
            scanf("%d%d",&b[i].num,&b[i].score);
        sort(a,a+n,cmp);
        sort(b,b+m,cmp);
        i=j=k=0;
        while(i<n&&j<m)
        {
            if(a[i].num<b[j].num)
                c[k++]=a[i++];
            else
                c[k++]=b[j++];
        }
        while(i<n)
            c[k++]=a[i++];
        while(j<m)
            c[k++]=b[j++];
        for(i=0;i<k;i++)
            printf("%d %d\n",c[i].num,c[i].score);
    }
    return 0;
}


 

 

posted @ 2013-10-12 22:08  Class Xman  阅读(169)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3