当前位置: 代码迷 >> C语言 >> 求助啊,浙大ACM第2481题
  详细解决方案

求助啊,浙大ACM第2481题

热度:129   发布时间:2007-07-22 14:21:13.0
求助啊,浙大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  

----------------解决方案--------------------------------------------------------

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


----------------解决方案--------------------------------------------------------
能通过几个case不证明你的算法就是正确的,我没看你写的因为格式太乱了。这题先排序再去重输出即可。
----------------解决方案--------------------------------------------------------