C# - Problems for Champions - Part II - 01. Passion Days, 2 грешки от Judge системата - Memory limit
Здравейте, колеги!
Бихти ли ми помогнали с моя код за тази задача. Вече няколко теста направих и винаги имам 80% успеваемост.
Благодаря предварително за отделеното време.
С поздрав,
Мариана Петкова
Ето го и кода:
using System;
using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace ShoppingNS
{
public class Shopping
{
public static void Main()
{
decimal shoppingMoney;
int numberRows = 0;
do
{
try
{
shoppingMoney = decimal.Parse(Console.ReadLine());
}
catch (Exception e)
{
Console.WriteLine("Incorect format for money or money are zero or negative.");
shoppingMoney = 0;
}
} while (shoppingMoney <= 0);
string command = Console.ReadLine();
while (command != "mall.Enter")
{
command = Console.ReadLine();
}
int purchases = 0;
decimal price = 0;
command = Console.ReadLine();
numberRows = 1;
while (command != "mall.Exit" && numberRows <= 20)
{
if (command.Length > 20)
{
command = command.Substring(0, 20);
}
foreach(char action in command)
{
if (action >= 'A' && action <= 'Z')
{
// Console.WriteLine("ASCII Cap: " + (int)action);
price = action * 0.5m;
if (shoppingMoney < price)
{
continue;
}
shoppingMoney -= price;
purchases++;
} else if (action >= 'a' && action <= 'z')
{
// Console.WriteLine("ASCII Small: " + (int)action);
price = action * 0.3m;
if (shoppingMoney < price)
{
continue;
}
shoppingMoney -= price;
purchases++;
} else if (action == '%')
{
// Console.WriteLine("ASCII %: " + (int)action);
if (shoppingMoney > 0)
{
price = shoppingMoney / 2.0m;
shoppingMoney -= price;
purchases++;
}
} else if (action == '*')
{
// Console.WriteLine("ASCII *: " + (int)action);
shoppingMoney += 10m;
} else
{
// Console.WriteLine("ASCII other: " + (int)action);
price = action;
if (shoppingMoney < price)
{
continue;
}
shoppingMoney -= price;
purchases++;
}
} // while foreach
command = Console.ReadLine();
numberRows++;
} // while mall.Exit
if (purchases == 0)
Console.WriteLine("No purchases. Money left: {0:0.00} lv.", shoppingMoney);
else
Console.WriteLine("{0} purchases. Money left: {1:0.00} lv.", purchases, shoppingMoney);
}
}
}