| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 836 人关注过本帖
标题:为什么只能输出一个测试用例啊,关于线性表的问题!
只看楼主 加入收藏
jj369258
Rank: 4
等 级:业余侠客
帖 子:116
专家分:226
注 册:2010-12-2
结帖率:69.57%
收藏
已结贴  问题点数:5 回复次数:3 
为什么只能输出一个测试用例啊,关于线性表的问题!
用A和B两个表分别存放A、B班的非递增排序的学习成绩,写一个算法,对两个班的学习成绩非递增总排序。约定数据元素为整型。


Input
第1行为一个整数t(1≤t≤10),表示接下来有t 个测试数据。 然后输入A班的学生人数,A班同学非递增排序的成绩;B班的学生人数,B班非递增排序的成绩。.

Output
总的学生成绩非递增排序的总表C。

Sample Input
2
10
98 95 93 90 90 88 85 80 78 67
12
96 95 92 91 89 89 88 86 84 81 80 80
5
97 85 77 62 55
8
88 82 81 80 79 77 76 73


Sample Output
98 96 95 95 93 92 91 90 90 89 89 88 88 86 85 84 81 80 80 80 78 67
97 88 85 82 81 80 79 77 77 76 73 62 55

代码:
#include<stdlib.h>
#include<iostream.h>
#include<conio.h>
typedef int ElemType;
#define LIST_INIT_SIZE 100
#define LISTNCREMENT 10
typedef struct
{
 int *elem;
 int length;
 int listsize;
}SqList;
int InitLlist_Sq(SqList &L)
{
 L.elem=(int*)malloc(LIST_INIT_SIZE*sizeof(int));
 if(!L.elem)
  return(0);
 L.length=0;
 L.listsize=LIST_INIT_SIZE;
 return(1);
}
int Merge_Sq(SqList &A,SqList &B,SqList &C)
{
 C.listsize=C.length=A.length+B.length;
 C.elem=(ElemType *)malloc(C.listsize *sizeof(ElemType ));
 int i=0,j=0,k=0;
 while((i<A.length)&&(j<B.length))
  if(A.elem[i]>=B.elem[j])
   C.elem[k++]=A.elem[i++];
  else
   C.elem[k++]=B.elem[j++];
  while(i<A.length)
   C.elem[k++]=A.elem[i++];
  while(i<B.length)
   C.elem[k++]=B.elem[i++];
  return 1;
}
void main()
{
 SqList A,B,C;
 int t;//表示有t个测试用例
 int j;
 cin>>t;
 for(j=0;j<t;j++)
 {
  InitLlist_Sq(A);
  InitLlist_Sq(B);
  InitLlist_Sq(C);
  cin>>A.length;
  for(j=0;j<A.length;j++)
   cin>>A.elem [j];
  cin>>B.length;
  for(j=0;j<B.length;j++)
   cin>>B.elem [j];
  Merge_Sq(A,B,C);
  for(j=0;j<C.length;j++)
   cout<<C.elem[j]<<" ";
  cout<<endl;
 }
}



 
搜索更多相关主题的帖子: 测试 学习 线性表 元素 
2011-09-29 10:20
bhu_wll
Rank: 3Rank: 3
来 自:北京
等 级:论坛游侠
帖 子:70
专家分:167
注 册:2011-9-8
收藏
得分:5 
#include<stdlib.h>
#include<iostream.h>
#include<conio.h>
typedef int ElemType;
#define LIST_INIT_SIZE 100
#define LISTNCREMENT 10
typedef struct
{
    int *elem;
    int length;
    int listsize;
}SqList;
int InitLlist_Sq(SqList &L)
{
    L.elem=(int*)malloc(LIST_INIT_SIZE*sizeof(int));
    if(!L.elem)
        return(0);
    L.length=0;
    L.listsize=LIST_INIT_SIZE;
    return(1);
}
int Merge_Sq(SqList &A,SqList &B,SqList &C)
{
    C.listsize=C.length=A.length+B.length;
    C.elem=(ElemType *)malloc(C.listsize *sizeof(ElemType ));
    int i=0,j=0,k=0;
    while((i<A.length)&&(j<B.length))
        if(A.elem[i]>=B.elem[j])
            C.elem[k++]=A.elem[i++];
        else
            C.elem[k++]=B.elem[j++];
        while(i<A.length)
            C.elem[k++]=A.elem[i++];
        while(i<B.length)
            C.elem[k++]=B.elem[i++];
        return 1;
}
void main()
{
    SqList A,B,C;
    int t;//表示有t个测试用例
    int j,i;
    cin>>t;
    for(i=0;i<t;i++)
    {
        InitLlist_Sq(A);
        InitLlist_Sq(B);
        InitLlist_Sq(C);
        cin>>A.length;
        for(j=0;j<A.length;j++)
            cin>>A.elem [j];
        cin>>B.length;
        for(j=0;j<B.length;j++)
            cin>>B.elem [j];
        Merge_Sq(A,B,C);
        for(j=0;j<C.length;j++)
            cout<<C.elem[j]<<" ";
        cout<<endl;
    }

}


努力对待生活
2011-09-29 10:35
bhu_wll
Rank: 3Rank: 3
来 自:北京
等 级:论坛游侠
帖 子:70
专家分:167
注 册:2011-9-8
收藏
得分:0 
循环体内用的j影响了循环体外的j,
以后记住不可以这么用。

努力对待生活
2011-09-29 10:38
jj369258
Rank: 4
等 级:业余侠客
帖 子:116
专家分:226
注 册:2010-12-2
收藏
得分:0 
回复 2楼 bhu_wll
谢谢
2011-09-30 19:18
快速回复:为什么只能输出一个测试用例啊,关于线性表的问题!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.041921 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved