YTU OJ C# 1636: FatMouse’ Trade
using System;
class Program
{
static void Main(String[] agrs)
{
string num;
string[] str;
var M = 0;
var N = 0;
method method = new method();
while (String.IsNullOrEmpty(num = Console.ReadLine()) == false)
{
str = num.Split(' ');
bool x = int.TryParse(str[0], out M);
bool y = int.TryParse(str[1], out N);
if (M == -1 && N == -1)
break;
string[] InFJ = new string[N];
for (var i=0;i<N;i++ )
{
InFJ[i] = Console.ReadLine();
}
method.printf(InFJ,M,N);
}
}
}
class method
{
public void printf(string[] str,int M,int N)
{
var catFu = M;
var jihao = 0;
string[] str1;
double max=0;
double[,] num = new double[N,2];
double[] bifen = new double[N];
double fu = 0;
for (var i=0;i<N;i++)
{
str1 = str[i].Split(' ');
bool x = double.TryParse(str1[0], out num[i,0]);
bool y = double.TryParse(str1[1], out num[i,1]);
}
for(var i=0;i<N;i++)
{
bifen[i] = (num[i, 0] / num[i, 1]);
}
while (catFu > 0)
{
for (var i = 0; i < N; i++)
{
if (bifen[i] > max)
{
max = bifen[i];
jihao = i;
}
}
if (catFu > num[jihao, 1] && catFu > 0)
{
catFu = (int)(catFu - num[jihao, 1]);
fu = fu + num[jihao,0];
}
else if (catFu < num[jihao, 1] && catFu > 0)
{
fu = fu + (catFu/num[jihao,1])*num[jihao,0];
catFu = 0;
}
bifen[jihao] = 0;
max = 0;
}
Console.WriteLine("{0:.000}",fu);
}
}