I need help with this puzzle of C#: Its a fill in the blanks game and the answers can be one of the following to the 7 spaces
我需要帮助解决这个C#难题:它填补了空白游戏,答案可以是7个空格中的以下之一
Blanks look like this _ and are highlighted & there are 7 of them
空白看起来像这样_并突出显示,其中有7个
The next part of the puzzle is What C# function can i call to replace the for loop and insert to satisfy ‘result == ?’ in the code below:
这个难题的下一部分是我可以调用什么C#函数来替换for循环和insert以满足下面代码中的'result ==?':
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!”);
Im guessing for this you will need somekind of linq query which will just fit in, but how ?
我猜这个你需要一些linq查询,它只适合,但是怎么样?
I'm personally mind blown since im not a fan of C#
因为我不是C#的粉丝,我个人心里都在吹嘘
2 个解决方案
#1
1
Solved. Basically just try out a few things, some other things are pretty logical (e.g. the while(wordCount < 4)
due to the wordCount
incrementing). Other things are just modulo arithmetic stuff which make the challenge a little bit harder. (Like x % 1
is always true
).
解决了。基本上只是尝试一些事情,其他一些事情是非常合乎逻辑的(例如,由于wordCount递增,while(wordCount <4))。其他的东西只是模数算术的东西,使挑战更难一点。 (像x%1总是如此)。
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!");
}
}
#2
0
Here is the last part ot the question: use string.Join
这是问题的最后一部分:使用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!");
#1
1
Solved. Basically just try out a few things, some other things are pretty logical (e.g. the while(wordCount < 4)
due to the wordCount
incrementing). Other things are just modulo arithmetic stuff which make the challenge a little bit harder. (Like x % 1
is always true
).
解决了。基本上只是尝试一些事情,其他一些事情是非常合乎逻辑的(例如,由于wordCount递增,while(wordCount <4))。其他的东西只是模数算术的东西,使挑战更难一点。 (像x%1总是如此)。
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!");
}
}
#2
0
Here is the last part ot the question: use string.Join
这是问题的最后一部分:使用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!");