标题:求助啊,浙大ACM第2481题
只看楼主
h330255029
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-7-22
 问题点数:0 回复次数:2 
求助啊,浙大ACM第2481题

原题:
Given an array of integers A[N], you are asked to decide the shortest array of integers B[M], such that the following two conditions hold.

For all integers 0 <= i < N, there exists an integer 0 <= j < M, such that A[i] == B[j]
For all integers 0 =< i < j < M, we have B[i] < B[j]
Notice that for each array A[] a unique array B[] exists.


Input

The input consists of several test cases. For each test case, an integer N (1 <= N <= 100) is given, followed by N integers A[0], A[1], ..., A[N - 1] in a line. A line containing only a zero indicates the end of input.


Output

For each test case in the input, output the array B in one line. There should be exactly one space between the numbers, and there should be no initial or trailing spaces.


Sample Input

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


Sample Output

1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3

我的解答是:
#include "stdio.h"
main()
{
int A[100],B[100],i,n,max,j,a,flag;
flag=1;
while(flag){
scanf("%d",&n);
if(n!=0){
for(i=0;i<n-1;i++){
scanf("%d ",&A[i]);
}
scanf("%d",&A[n-1]);
a=0;
for(j=1;j<=100;j++){
for(i=0;i<n;i++){
if(j==A[i]){
B[a]=j;
a++;
break;
}
}
}
for(i=0;i<a-1;i++){
printf("%d ",B[i]);
}
printf("%d\n",B[a-1]);
flag=1;
}
if(n==0){
flag=0;
}
}
}

为何我运行过是可以的,提交上去的时候却出现wrong answer呢?求高人解答。。。

搜索更多相关主题的帖子: ACM left align test The 
2007-07-22 14:21
h330255029
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-7-22
得分:0 

在线等啊。。。高手们。。。

2007-07-22 14:41
leeco
Rank: 4
等 级:贵宾
威 望:10
帖 子:1026
专家分:177
注 册:2007-5-10
得分:0 
能通过几个case不证明你的算法就是正确的,我没看你写的因为格式太乱了。这题先排序再去重输出即可。
2007-07-23 20:58



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-157241-1-1.html




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

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