我一直在試圖解決這個黑客練習題(Compare the Triplets),我不知道我錯在哪裏。我的輸出是正確的,但它並沒有通過hackerrank的所有測試用例。有什麼建議?比較三胞胎C#hackerrank改進我的解決方案
問題:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {
static void Main(String[] args) {
string[] tokens_a0 = Console.ReadLine().Split(' ');
int a0 = Convert.ToInt32(tokens_a0[0]);
int a1 = Convert.ToInt32(tokens_a0[1]);
int a2 = Convert.ToInt32(tokens_a0[2]);
string[] tokens_b0 = Console.ReadLine().Split(' ');
int b0 = Convert.ToInt32(tokens_b0[0]);
int b1 = Convert.ToInt32(tokens_b0[1]);
int b2 = Convert.ToInt32(tokens_b0[2]);
// Write Your Code Here
int aliceScore = 0;
int bobScore = 0;
if(a0 > b0 || a1 > b1 || a2 > b2)
{
aliceScore++;
}
if(b0 > a0 || b1 > a1 || b2 > a2)
{
bobScore++;
}
if(a0 == b0 || a1 == b1 || a2 == b2)
{
aliceScore += 0;
bobScore += 0;
}
Console.WriteLine(aliceScore +" " + bobScore);
}
}
我認爲你的3rd if語句沒有任何用處。 – GER
在你的版本中,任何一個玩家只能有0或1分。這顯然是錯誤的 – UnholySheep
讓您的代碼在問題 – Alyafey