握手问题【难度:2级】:
答案1:
using System;
public static class Kata
{
public static int GetParticipants(int handshakes)
{
if (handshakes==0)
return 1;
int sqrt =(int)Math.Sqrt(handshakes*2);
for (int i = sqrt; i <= sqrt+9; i++)
{
if (i*(i-1)>=handshakes*2)
{
return i;
}
}
return -1;
}
}
答案2:
using System;
public static class Kata
{
public static int GetParticipants(int handshakes)
{
string a = handshakes.ToString();
int counter = 0;
int i = 0;
int[] farmers = new int[a