2016-01-24 20 views
-3

This is the whole puzzleC#之謎,無法弄明白

我需要這個難題的C#幫助:它在毛坯遊戲填充和答案可以是以下這7位

之一

空白這個樣子_和突出&有他們

拼圖的下一部分的7 我可以叫什麼C#功能來代替for循環,並插入到滿足「結果== ?'代碼如下:

var answer = "Please help me with this puzzle please"; 

    var words = new[] { "Please", "help", "me", "with", "this", "puzzle", "please" }; 

    var result = ? 

    if (result == answer) 
    Console.WriteLine(「Correct!」); 

我猜這個,你將需要一些linq查詢,這將適合,但如何?

我個人很頭腦,因爲我不是C的粉絲#

+4

邁克,至少有正確的縮進寫下來,並確保你已經得到了所有的括號的權利。 –

+0

一切都是重複檢查是正確的我不會錯過任何東西,除非你能發現特別的東西 – Michael

+0

我改變了它並上傳了圖像我有拼圖,而不是自己寫,因爲我是一個初學者在stackflow和即時通訊一個學生我不是很好與stackflow和縮進代碼,抱歉的傢伙,但我仍然可以使用你所有的幫助 – Michael

回答

1

解決了。基本上只是嘗試一些事情,其他一些事情是非常合理的(例如,由於wordCount遞增而導致的while(wordCount < 4))。其他的東西只是模數算術的東西,這使挑戰有點困難。 (像x % 1總是true)。

using System; 

class Programm 
{ 
    static void Main() 
    { 
     var answer = "Please help me with this puzzle please"; 
     var words = new[] { "Please", "help", "me", "with", "this", "puzzle", "please" }; 

     var result = ""; 
     var wordCount = 0; 

     for (var iCount = 12; iCount > 0; iCount--) 
     { 
      while (wordCount < 4) //less than because word count get's incremented 
      { 
       if (iCount % 1 == 0) 
       { 
        result += words[wordCount]; 
        result += " "; 
        wordCount++; 
       } 

       if ((iCount * 6) == 24) 
       { 
        result += words[wordCount]; 
        result += " "; 
        wordCount++; 
       } 
       iCount--; 
      } 

      if (iCount % 3 != 1) 
       continue; 

      result += words[wordCount]; 

      if (wordCount != 6) 
       result += " "; 

      wordCount += 1; 
     } 

     Console.WriteLine("Result: " + result); 

     if (result == answer) 
      Console.WriteLine("Correct!"); 
     else 
      Console.WriteLine("FAIL!"); 
    } 
} 
+0

我會使用某種linq查詢來解決問題的最後部分,那是我可以通過研究找出替代for循環? – Michael

0

這裏是最後加時賽的問題:使用string.Join

var answer = "Please help me with this puzzle please"; 

    var words = new[] { "Please", "help", "me", "with", "this", "puzzle", "please" }; 

    var result = string.Join(" ", words); 

    if (result == answer) 
     Console.WriteLine("Correct!"); 
+0

爲什麼不會是一個linq查詢? – Michael

+0

因爲這是「一個簡單的C#函數」。事實上,這是你可以做到的最簡單的目標。 LINQ查詢會更復雜。 –

+0

好的,謝謝你的幫助,我真的很欣賞它 – Michael