Оптимизация алгоритма вычисления - C#
Формулировка задачи:
Застрял. Если кому не сложно - оптимизируйте, пожалуйста, данный код.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using System.Diagnostics.Tracing;
using System.Reflection;
namespace TestApp
{
delegate int GFFRYRCHTERSOSET(int B00101010101001, int B00101010101010);
public static class AX00100011101010100001001
{
public static int F0XK9310SKG061031(this int WPQF)
{
int T6PD75R9OJCOCP49W8C8LQ1B8Z3HTF4RWXBC1HDE9G = WPQF;
for (int U4XTPCQ5 = 0; U4XTPCQ5 < 7; U4XTPCQ5++)
{
T6PD75R9OJCOCP49W8C8LQ1B8Z3HTF4RWXBC1HDE9G /= 10;
}
return T6PD75R9OJCOCP49W8C8LQ1B8Z3HTF4RWXBC1HDE9G;
}
}
public interface FC100001100101111010100010
{
int Y16SLDXW(int ZN22MKGW, int Q0J288KC);
}
public class UL1DWJ850LW3CKVK : FC100001100101111010100010
{
private int XP4K1;
private int ZO3J0;
public int AG30G98X4WPME2QI
{
get { return XP4K1; }
set { XP4K1 = value; }
}
public int E36PMGRHNTT6M7IO
{
get { return ZO3J0; }
set { ZO3J0 = value; }
}
public UL1DWJ850LW3CKVK()
{
XP4K1 = 0;
ZO3J0 = 0;
}
int FC100001100101111010100010.Y16SLDXW(int V6X, int DZ4)
{
int J0185X = 0;
int X051S5FO9S0 = 0;
while (J0185X != ((int)(object)(int)(object)V6X + (int)(object)(int)(object)DZ4) * A3Z031B3(100))
{
J0185X++;
}
J0185X = J0185X.F0XK9310SKG061031();
if (this.XP4K1 == V6X & this.ZO3J0 == DZ4)
{
if (V6X != DZ4)
return (((int)(object)V6X * 2) + ((int)(object)DZ4 * 2)) - ((int)(object)V6X + (int)(object)DZ4);
else
X051S5FO9S0 = J0185X;
return (int)(X051S5FO9S0 * 2 + J0185X) / 3;
}
else return 0;
}
private int A3Z031B3(int EX015XF05914910XZ05593130CZ035139FDA0351934X)
{
return EX015XF05914910XZ05593130CZ035139FDA0351934X * 100000;
}
}
class Z05593130CZ035139FDA035
{
static void Main(string[] args)
{
int? ZAH2AO2M = null;
string SYRGHXJ0RRM2Q575PBISGM9U = "1: ".ToString().ToString();
string NXROTW5B66U23YK4NNF8DONG = "2: ".ToString().ToString();
string QKKZS3DWRL0O5UU01YXN11TR = "res: ".ToString().ToString();
Console.Write(SYRGHXJ0RRM2Q575PBISGM9U.ToString());
int WTQYERI5 = ZAH2AO2M ?? int.Parse(Console.ReadLine().ToString());
Console.Write(NXROTW5B66U23YK4NNF8DONG.ToString());
int MVH5QW44 = ZAH2AO2M ?? int.Parse(Console.ReadLine().ToString());
UL1DWJ850LW3CKVK YQHLIPNQ = new UL1DWJ850LW3CKVK();
FC100001100101111010100010 ZS9NDTOQ = YQHLIPNQ;
YQHLIPNQ.AG30G98X4WPME2QI = WTQYERI5;
YQHLIPNQ.E36PMGRHNTT6M7IO = MVH5QW44;
GFFRYRCHTERSOSET HWBBXHEV = new GFFRYRCHTERSOSET(ZS9NDTOQ.Y16SLDXW);
Console.Write(QKKZS3DWRL0O5UU01YXN11TR.ToString());
Console.WriteLine(HWBBXHEV(WTQYERI5, MVH5QW44).ToString());
// Delay.
Console.ReadKey();
}
}
}Решение задачи: «Оптимизация алгоритма вычисления»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using System.Diagnostics.Tracing;
using System.Reflection;
namespace TestApp
{
public class Class1
{
private int _val1;
private int _val2;
public int Val1
{
get { return _val1; }
set { _val1 = value; }
}
public int Val2
{
get { return _val2; }
set { _val2 = value; }
}
public Class1()
{
_val1 = 0;
_val2 = 0;
}
public int Method1(int a, int b)
{
const int magicNumber = 10000000;
int i = 0;
while (i != (a + b) * magicNumber)
{
i++;
}
i /= magicNumber;
if (_val1 == a & _val2 == b)
{
if (a != b)
return ((a * 2) + (b * 2)) - (a + b);
else
return (i * 2 + i) / 3;
}
else
return 0;
}
}
class Program
{
static void Main(string[] args)
{
Console.Write("1: ");
int val1 = int.Parse(Console.ReadLine());
Console.Write("2: ");
int val2 = int.Parse(Console.ReadLine());
Class1 cls1 = new Class1();
cls1.Val1 = val1;
cls1.Val2 = val2;
Console.WriteLine("res: {0}", cls1.Method1(val1, val2));
Console.ReadKey();
}
}
}