以下のコードは正常に動作します。唯一の問題は、長さが200,000の配列値を与えると、約1時間で完了するのに時間がかかりすぎるということです。以下は私のコードです。forループの終了に多くの時間がかかります
データファイルhereには、dataとdata2の文字列値が含まれています。 データ配列は降順に並べ替えられ、data2は昇順に並べ替えられます。
public void GetInputs()
{
string data;
string data2;
string[] scores_temp = data.Split(' ');
int[] scores = Array.ConvertAll(scores_temp, Int32.Parse);
string[] alice_temp = data2.Split(' ');
int[] aliceScore = Array.ConvertAll(alice_temp, Int32.Parse);
var distinctScores = scores.Distinct().ToList();
int rank = 0;
for (int j = 0; j <= aliceScore.Length-1; j++)
{
for (int i = distinctScores.Count-1; i >= 0; i--)
{
if (aliceScore[j] >= distinctScores[i])
{
rank = distinctScores.IndexOf(distinctScores[i]);
}
else if (aliceScore[j] < distinctScores[i])
{
rank = distinctScores.IndexOf(distinctScores[i]);
rank += 2;
break;
}
}
if (rank.ToString() == "0") {
Console.WriteLine(rank.ToString().Replace("0", "1"));
} else {
Console.WriteLine(rank); };
}
Console.ReadLine();
}
どのくらい長いですか? –
約1時間.. – maxspan
'data'と' data2'はどこに割り当てられますか? –