| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 731 人关注过本帖
标题:请问一个C语言问题 - - 一直【Presentation Error】
只看楼主 加入收藏
titus
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-2-4
结帖率:0
收藏
已结贴  问题点数:10 回复次数:5 
请问一个C语言问题 - - 一直【Presentation Error】
Description
Give a set of numbers, output them after sort. You may use any algorithm you like to solve it.
Input
Each input file contains only one case.
Each test case begins with an integer N(0<N<=1000), the size of the set.
The Next line contains N numbers, represent the elements of the set. Each number range in [0..65535]
Output
Output the set in one line after sort.
Each pair of adjacent numbers is separated by one space. There is no space but '\n' at the end of the line.
Sample Input
4
4 15 8 5
Sample Output
4 5 8 15

我的解法 - -
#include<stdio.h>   
int main()   
{   
    int a[50];   
    int l,i,j,t;   
    scanf("%d",&l);   
    for(i=0;i<l;i++)   
        scanf("%d",&a[i]);   
    printf("\n");   
    for(j=0;j<l-1;j++)   
        for(i=0;i<l-j-1;i++)   
            if(a[i]>a[i+1])   
            {   
                t=a[i];   
                a[i]=a[i+1];   
                a[i+1]=t;   
            }   
            for(i=0;i<l;i++)   
                printf("%d ",a[i]);   
            printf("\n");   
  
}  
oj表示【Presentation Error】···
请问是哪里出问题了呢 看了老半天了
搜索更多相关主题的帖子: set only represent elements numbers 
2013-02-17 22:34
心灯甚亮
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:2
帖 子:441
专家分:996
注 册:2013-1-29
收藏
得分:10 
看缩进,大概是你最后一行的printf()出嫁了
2013-02-17 22:46
titus
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-2-4
收藏
得分:0 
回复 2楼 心灯甚亮
- - 不懂啊
2013-02-17 23:07
titus
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-2-4
收藏
得分:0 
终于解决了 - - 菜鸟好开心
#include<stdio.h>      
int main()      
{      
    int a[1001];      
    int l,i,j,t;      
    scanf("%d",&l);      
    for(i=0;i<l;i++)      
        scanf("%d",&a[i]);      
      
    for(j=0;j<l-1;j++)      
        for(i=0;i<l-1;i++)      
            if(a[i]>a[i+1])      
            {      
                t=a[i];      
                a[i]=a[i+1];      
                a[i+1]=t;      
            }      
               
                for(i=0;i<l;i++)     
                   if(i<l-1)   
                   {   
                       printf("%d ",a[i]);   
                   }   
             else printf("%d\n",a[i]);   
     return 0;   
               
}  
 改正:1.去掉了 输出时的前一个换行  2.输出l-1个后带空格的数之后再输出最后一个数且带换行 3.开大数组范围(由50改为1001)

[ 本帖最后由 titus 于 2013-2-18 00:20 编辑 ]
2013-02-18 00:18
心灯甚亮
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:2
帖 子:441
专家分:996
注 册:2013-1-29
收藏
得分:0 
这就是了嘛
2013-02-18 07:28
心灯甚亮
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:2
帖 子:441
专家分:996
注 册:2013-1-29
收藏
得分:0 
不过打回车完全可以不用条件判断 试着改改 加油
2013-02-18 07:32
快速回复:请问一个C语言问题 - - 一直【Presentation Error】
数据加载中...
 
   



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

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