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) ;
}
}
}
05-11 23:01