var array = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Console.WriteLine(string.Join(" ", array));
var last = array.Last(); //берем последний элемент
array.Remove(last); //удаляем его
array.Insert(0, last); //и добавляем в начало, все элементы сдвигаются и, соответственно, меняют четность позиции
Console.WriteLine(string.Join(" ", array));
var array = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Console.WriteLine(string.Join(" ", array));
for (int i = 0; i < array.Count - 1; i += 2)
{
//Меняем соседние элементы местами
array[i] ^= array[i + 1];
array[i + 1] ^= array[i];
array[i] ^= array[i + 1];
}
Console.WriteLine(string.Join(" ", array));
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
namespace ConsoleApplication11
{
class Test
{
public string P1 { get; set; }
public int P2 { get; set; }
}
class Program
{
static void Main(string[] args)
{
var str = JsonConvert.SerializeObject(new List<object> {
new { s = true, P1 = "one", P2 = 12 },
new { s = false, P1 = "two", P2 = 13 },
new { s = true, P1 = "three", P2 = 14 } });
dynamic dObject = JsonConvert.DeserializeObject(str);
var list = new List<Test>();
foreach (var item in dObject)
{
if (item.s == true)
{
list.Add(item.ToObject<Test>());
}
else
{
Console.WriteLine("No way");
}
}
Console.ReadKey();
}
}
}
using System;
using System.Numerics;
using System.Globalization;
namespace Hippogriffs
{
class Class1
{
public static int a1, b1, a2, b2; //функция находящая влияние эликсира на конкретного гиппогрифа с параметрами A и B
public static long mnozitel = 1000000000;
public static BigInteger GetElixirPower(BigInteger A, BigInteger B) { return (BigInteger.Pow(A * a1 + B * b1, 2) + BigInteger.Pow(A * a2 + B * b2, 2)) * BigInteger.Pow(mnozitel, 2) / (BigInteger.Pow(A, 2) + BigInteger.Pow(B, 2)); }
static void Main(string[] args)
{
var line = Console.ReadLine();//считывание переменных с клавиатуры: считываем строку, разделяем её в том месте, где находится пробел
a1 = Int32.Parse(line.Split(' ')[0]);
b1 = Int32.Parse(line.Split(' ')[1]);
line = Console.ReadLine();
a2 = Int32.Parse(line.Split(' ')[0]);
b2 = Int32.Parse(line.Split(' ')[1]); //берём некие случайные A и B(x и y), например 100
long A = (100 * mnozitel);
long B = (100 * mnozitel);
BigInteger currentPower = new BigInteger((double)GetElixirPower(A, B)); //объяляем переменную с помощью которой будем "шагать"
long distance = mnozitel;
while (distance > 1)
{
BigInteger bestPower = currentPower;
long bestX = -1;
long bestY = -1; //массивы с направлениями (в + по х, в - по х, в + по у, в - по у)
long[] directionsX = { distance, -distance, 0, 0 };
long[] directionsY = { 0, 0, distance, -distance }; //шагаем в 4 направления
for (int i = 0; i < 4; i++)
{ //координаты места, куда шагаем
long checkX = A + directionsX[i];
long checkY = B + directionsY[i]; //проверка на случа шага вне положительных значений
if (checkX <= 0 || checkY <= 0) { continue; } //проверка опасности с такими параметрами
BigInteger checkPower = new BigInteger((double)GetElixirPower(checkX, checkY)); //если в точках опасность больше, то переходим окончательно в ту точку
if (checkPower > bestPower) { bestPower = checkPower; bestX = checkX; bestY = checkY; }
} //если bestX не равен -1, это значит что мы куда то двигались
if (bestX != -1)
{
currentPower = bestPower; A = bestX; B = bestY;
Console.WriteLine("Current power is equals " + currentPower.ToString("0.000000000000000") + " at x: " + A.ToString("0.00000000000000") + " y: " + B.ToString("0.00000000000000"));
}
else { distance = distance * 90 / 100; }
}
double result = Math.Sqrt((double)currentPower) / mnozitel;
Console.WriteLine(result.ToString("0.000000000", CultureInfo.InvariantCulture));
}
}
}