sort

Time Limit: 6000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 39400    Accepted Submission(s): 11450

Problem Description
给你n个整数,请按从大到小的顺序输出其中前m大的数。
 
Input
每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且都处于区间[-500000,500000]的整数。
 
Output
对每组测试数据按从大到小的顺序输出前m大的数。
 
Sample Input
5 3
3 -35 92 213 -644
 
Sample Output
213 92 3

Hint

Hint

请用VC/VC++提交

 
Author
LL
 
Source
题解:好疑惑,自己的代码有毒,在hdoj能过,virtrual judge 就不行,c#也老是wa。。。
c代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN = ;
int a[MAXN];
int cmp(int x,int y){
return x > y;
}
int main(){
int n,m;
while(~scanf("%d%d",&n,&m)){
for(int i = ;i < n;i++){
scanf("%d",&a[i]);
}
sort(a,a + n, cmp);
for(int i = ; i < m;i++){
if(i)printf(" ");
printf("%d",a[i]);
}
puts("");
}
return ;
}

C#  wa了:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections; namespace sort
{
class Program
{
static int input()
{
int x = , k = ;
int temp;
while (true)
{
temp = Console.Read();
if (temp >= '' && temp <= '')
break;
else if(temp == '-')
{
k = -;
temp = '';
break;
}
}
while (true)
{
x = x * + temp - '';
temp = Console.Read();
if (temp < '' || temp > '') break;
}
// Console.WriteLine("{0}",x * k);
return x * k;
}
static void Main(string[] args)
{
int n, m;
n = input();
m = input();
ArrayList arr = new ArrayList();
arr.Clear();
while (n-- > )
{
int x;
x = input();
arr.Add(x);
}
arr.Sort();
for(int i = ; i <= m; i++)
{
if (i != ) Console.Write(" ");
Console.Write("{0}",arr[arr.Count - i]);
}
Console.WriteLine();
//while (true) ;
}
}
}

sort(水题)的更多相关文章

  1. Codeforces Gym 100431D Bubble Sort 水题乱搞

    原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-an ...

  2. CF451B Sort the Array 水题

    Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...

  3. CF451C Predict Outcome of the Game 水题

    Codeforces Round #258 (Div. 2) Predict Outcome of the Game C. Predict Outcome of the Game time limit ...

  4. poj 1007:DNA Sorting(水题,字符串逆序数排序)

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 80832   Accepted: 32533 Des ...

  5. URAL - 1917 Titan Ruins: Deadly Accuracy(水题)

    水题一个,代码挫了一下: 题意不好理解. 你去一个洞窟内探险,洞窟内有许多宝石,但都有魔法守护,你需要用魔法将它们打下来. 每个宝石都有自己的防御等级,当你的魔法超过它的防御等级时它就会被你打下来. ...

  6. 水题 ZOJ 3875 Lunch Time

    题目传送门 /* 水题:找排序找中间的价格,若有两个,选价格大的: 写的是有点搓:) */ #include <cstdio> #include <iostream> #inc ...

  7. 水题 ZOJ 3869 Ace of Aces

    题目传送门 水题,找出出现次数最多的数字,若多个输出Nobody //#include <bits/stdc++.h> //using namespace std; #include &l ...

  8. 【BZOJ】3850: ZCC Loves Codefires(300T就这样献给了水题TAT)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3850 题意:类似国王游戏....无意义.. #include <cstdio> #inc ...

  9. 【wikioi】1229 数字游戏(dfs+水题)

    http://wikioi.com/problem/1229/ 赤裸裸的水题啊. 一开始我认为不用用完全部的牌,以为爆搜会tle.. 可是我想多了. 将所有状态全部求出,排序后暴力判断即可. (水题有 ...

随机推荐

  1. qsort的几种用法

    #include<stdio.h> #include<stdlib.h> int cmp(const void *a,const void *b){ return *(int ...

  2. Oracle Enterprise linux 7 安装Oracle11gR2

    一.修改主机名和IP地址: [root@localhost Desktop]# cat /etc/hosts127.0.0.1 localhost.localdomain localhost 192. ...

  3. 【中途相遇+二进制】【NEERC 2003】Jurassic Remains

    例题25  侏罗纪(Jurassic Remains, NEERC 2003, LA 2965) 给定n个大写字母组成的字符串.选择尽量多的串,使得每个大写字母都能出现偶数次. [输入格式] 输入包含 ...

  4. nginx错误日志级别

    在配置nginx.conf 的时候,有一项是指定错误日志的,默认情况下你不指定也没有关系,因为nginx很少有错误日志记录的.但有时出现问题时,是有必要记录一下错误日志的,方便我们排查问题.error ...

  5. ffmpeg调试相关知识点

    1.若要调试FFMPEG,在编译时应当在configure时,加上 --enable-debug --disable-asm 注:在调试x264时就应该加上这两个配置选项,方能调试 2.make in ...

  6. PropertyGrid—添加属性Tab

    零.引言 PropertyGrid用来显示和编辑对象的属性,前面已经简单介绍了如何使用该控件和提供不同的属性编辑方法.前面主要讲如何使用该控件,但有时,该控件无法满足我们的需求,就需要对其进行扩展.本 ...

  7. 利用JPEGImageEncoder进行简单的图片压缩

    import java.awt.Dimension; import java.awt.Image; import java.awt.image.BufferedImage; import java.i ...

  8. JSP EL表达式详细介绍(转)

    转自:http://www.jb51.net/article/20042.htm 为了使JSP写起来更加简单. 表达式语言的灵感来自于 ECMAScript 和 XPath 表达式语言,它提供了在 J ...

  9. DataSet 图解

    DataSet层次结构中的类请参见表所示: 类 说明 DataTableCollection 包含特定数据集的所有DataTable对象 DataTable 表示数据集中的一个表 DataColumn ...

  10. css基础之 联网使用bootstrap

    在<head></head>中添加 <meta charset="utf-8"> <meta http-equiv="X-UA- ...