首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

ZOJ 【水题】排序程序输出结果是对的,wrong answer!该怎么处理

2013-03-26 
ZOJ 【水题】排序程序输出结果是对的,wrong answer!#includestdio.h#includestring.hint main(){int a[1

ZOJ 【水题】排序程序输出结果是对的,wrong answer!

#include<stdio.h>
#include<string.h>

int main()
{
int a[100],n,i,j,t,min;
while(scanf("%d",&n)!=EOF&&n)
{
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)  /*冒泡排序*/
{
min=i;
for(j=n-1;j>i;j--)
{
if(a[j]<a[min])
min=j;
}
           if(min!=i)
   {
   t=a[i]; a[i]=a[min];a[min]=t;
   }

}

       
        printf("%d",a[0]);
        for(i=1;i<n;i++)           /*输出*/
{
if(a[i]==(a[i-1]+1))       /*如果1,2 或者2,3,后一位比前一位大1,则输出*/
printf(" %d",a[i]);
else
if(a[i]==a[i-1]) /*如果1,1,1这种都相同的情况,不输出,继续for循环*/
;
else   /*否则,跳出循环*/
 break;
}
printf("\n");
}

return 0;
}


按照的input输入过,output都是一样的,但是它说 wrong answer???求解!
zoj 的 2481


Unique Ascending Array
Time Limit: 2 Seconds      Memory Limit: 65536 KB
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
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1481
按照的input输入过,output都是一样的,但是它说 wrong answer???求解!
zoj 的 2481

input
[解决办法]
引用:
引用:你只考虑了例子,没有考虑一般情况


没有,它说只有一个0,是它输入只有一个零。
我还有一种代码,是通过的,就是在这个没通过

还有个代码0也不这样处理的C/C++ code?1234567891011121314151617181920212223242526272829303132333435363738394041#incl……


0的问题是小问题,我当时考虑的是输入的数值不满足题意的情况。
后来看了下你贴出来的程序,你只判断了数值连续变化的情况,没有考虑排序后不是跳跃变化的情况
[解决办法]
我感觉有的acm题你做出来了就ok,然后自己弄几个好的测试用例测试过了就行,没必要非要AC

热点排行