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. ZOJ 1136 Multiple (BFS)

    Multiple Time Limit: 10 Seconds      Memory Limit: 32768 KB a program that, given a natural number N ...

  2. java Socket 使用注意

    Socket s = new Socket(ia, port); BufferedOutputStream bufOut = new BufferedOutputStream(s.getOutputS ...

  3. jQuery.extend()、jQuery.fn.extend()扩展方法示例详解

    jQuery自定义了jQuery.extend()和jQuery.fn.extend()方法.其中jQuery.extend()方法能够创建全局函数或者选择器,而jQuery.fn.extend()方 ...

  4. C#集合-队列

    本文来自:http://www.cnblogs.com/yangyancheng/archive/2011/04/28/2031615.html 队列是其元素以先进先出(FIFO)的方式来处理的集合. ...

  5. lua 类继承和实现

    http://blog.csdn.net/ssihc0/article/details/7742323 Account={balance=}; --新建了一个对像,他有一个属性balance func ...

  6. DOS窗口中文显示乱码

    记得以前的dos是可以显示中文的,但是今天复制东西发现竟然不能显示中文了,遇见中文就成了? 在右键->默认值中的默认代码页也显示有中文GBK,但是不管用 在右键->属性中的当前代码页显示为 ...

  7. H5单页面架构:自定义路由 + requirejs + zepto + underscore

    angular优点: 强大的数据双向绑定 View界面层组件化 内置的强大服务(例如表单校验) 路由简单 angular缺点: 引入的js较大,对移动端来说有点吃不消 语法复杂,学习成本高 backb ...

  8. c# 面相对象2-之封装性

    一.封装特性: 这是一种隐藏的特性.可以用一个公式来展示类的封装特性: 封装的类=数据  +  对此数据进行的操作(即算法) 通俗的说,封装就是:包起外界不必要知道的东西,只向外界展露可供展示的东西. ...

  9. QJson 的使用

    下载 源码解压 https://github.com/flavio/qjson 复制 src 目录下所有 .h .cpp .hh 文件到项目目录 qjson,pro 文件添加 INCLUDEPATH ...

  10. 理解ThreadLocal(一)

    早在JDK 1.2的版本中就提供java.lang.ThreadLocal,ThreadLocal为解决多线程程序的并发问题提供了一种新的思路.使用这个工具类可以很简洁地编写出优美的多线程程序. Th ...