想要买到争车位中所有的车型需要多少天?
争车位中购买所有车型需要天数计算的代码。
每12小时换一次车位的话,大约需要152天;
每15分钟换一次车位的话,大约需要136天。
我的代码如下,欢迎指点:
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyCars
{
class Program
{
static void Main(string[] args)
{
CarCaculator carc = new CarCaculator();
int total = 0;
while (true)
{
int days = carc.WinNextCar();
if (days == 0)
break;
total += days;
}
Console.WriteLine("Total Days:" + total / (60 * 24));
Console.ReadLine();
}
public class Car
{
public string Name { get; set; }
public int Price { get; set; }
}
public class CarCaculator
{
#region all cars
private readonly List<Car> _allCars = new List<Car>{ new Car { Name = "奥拓 二手奥拓", Price = 16000},
new Car { Name = "奥拓 奥拓小王子", Price = 20000},
new Car { Name = "夏利 夏利", Price = 32000},
new Car { Name = "奇瑞 奇瑞QQ", Price = 36000},
new Car { Name = "雪佛兰 SPARK乐驰", Price = 45800},
new Car { Name = "吉利 吉利自由舰", Price = 48000},
new Car { Name = "富康 富康", Price = 62000},
new Car { Name = "雨燕 雨燕", Price = 69000},
new Car { Name = "标致 标致206", Price = 78000},
new Car { Name = "雪铁龙 雪铁龙C2", Price = 79000},
new Car { Name = "MG 名爵3SW", Price = 79800},
new Car { Name = "大众 桑塔纳", Price = 80000},
new Car { Name = "大众 POLO", Price = 91000},
new Car { Name = "福田 福田欧马可", Price = 98800},
new Car { Name = "别克 别克凯越", Price = 105000},
new Car { Name = "标致 标致307", Price = 110000},
new Car { Name = "大众 宝来", Price = 116000},
new Car { Name = "起亚 赛拉图", Price = 127800},
new Car { Name = "福特 福特福克斯", Price = 128000},
new Car { Name = "本田 飞度", Price = 129800},
new Car { Name = "冒牌警车 冒牌警车", Price = 130000},
new Car { Name = "丰田 卡罗拉", Price = 132000},
new Car { Name = "大众 速腾", Price = 138000},
new Car { Name = "大众 高尔夫", Price = 139000},
new Car { Name = "本田 本田CIVIC", Price = 140000},
new Car { Name = "日产 骐达", Price = 149800},
new Car { Name = "大众 朗逸", Price = 149800},
new Car { Name = "雪铁龙 新毕加索", Price = 157800},
new Car { Name = "大众 帕萨特", Price = 186000},
new Car { Name = "酷派 现代酷派", Price = 190000},
new Car { Name = "大众 迈腾", Price = 198000},
new Car { Name = "本田 雅阁", Price = 199000},
new Car { Name = "福特 S-MAX", Price = 219800},
new Car { Name = "斯巴鲁 斯巴鲁翼豹", Price = 239800},
new Car { Name = "福特 蒙迪欧-致胜", Price = 239800},
new Car { Name = "本田 本田CRV", Price = 239800},
new Car { Name = "现代 途胜", Price = 241800},
new Car { Name = "大众 甲壳虫", Price = 250000},
new Car { Name = "奥迪 奥迪A4", Price = 280000},
new Car { Name = "哈雷 哈雷摩托", Price = 300000},
new Car { Name = "Mini Copper Mini Cooper", Price = 320000},
new Car { Name = "宝马 宝马320", Price = 330000},
new Car { Name = "切诺基", Price = 420000},
new Car { Name = "JEEP 牧马人", Price = 525000},
new Car { Name = "宝马 宝马Z4", Price = 568000},
new Car { Name = "奥迪 奥迪A6", Price = 620000},
new Car { Name = "奥迪 奥迪TT", Price = 645000},
new Car { Name = "悍马 悍马", Price = 800000},
new Car { Name = "凯迪拉克 凯迪拉克", Price = 878000},
new Car { Name = "宝马 宝马730", Price = 1080000},
new Car { Name = "沃尔沃 沃尔沃XC90", Price = 1138000},
new Car { Name = "奥迪 奥迪Q7", Price = 1232000},
new Car { Name = "路虎 路虎", Price = 1280000},
new Car { Name = "宝马 宝马X5", Price = 1336000},
new Car { Name = "林肯 林肯加长", Price = 1380000},
new Car { Name = "保时捷 保时捷911", Price = 1500000},
new Car { Name = "奔驰 RIMOR奔驰房车", Price = 1500000},
new Car { Name = "保时捷 保时捷卡宴", Price = 1520000},
new Car { Name = "大众 途锐", Price = 1580000},
new Car { Name = "雷克萨斯 雷克萨斯LS600", Price = 1598000},
new Car { Name = "奥迪 奥迪R8", Price = 1599000},
new Car { Name = "玛莎拉蒂", Price = 1790000},
new Car { Name = "奔驰 奔驰S600", Price = 2000000},
new Car { Name = "奔驰 奔驰豪华大巴", Price = 2500000},
new Car { Name = "法拉利 法拉利F430", Price = 3200000},
new Car { Name = "兰博基尼 兰博基尼", Price = 3980000},
new Car { Name = "马自达 马自达", Price = 6178000},
new Car { Name = "迈巴赫 迈巴赫62", Price = 6180000},
new Car { Name = "劳斯莱斯 劳斯莱斯", Price = 6200000},
new Car { Name = "帕加尼 帕加尼", Price = 12990000},
new Car { Name = "宾利 雅致728", Price = 13880000},
new Car { Name = "EB 布加迪威龙", Price = 25000000}};
#endregion
public CarCaculator()
{
_cars = new List<Car>();
_cars.Add(_allCars[0]);
}
private List<Car> _cars = new List<Car>();
public List<Car> Cars
{
get { return _cars; }
}
public bool IsFinished()
{
return _cars.Count == _allCars.Count;
}
public int MinutesPerUnit { get { return 15 * 48; } }
public int WinNextCar()
{
if (IsFinished())
return 0;
int price = _allCars[_cars.Count].Price;
int money = _cars.Count * (MinutesPerUnit * 10);
int minutes = (int)Math.Ceiling(price * 1.0F / money) * MinutesPerUnit;
_cars.Add(_allCars[_cars.Count]);
Console.WriteLine(_cars[_cars.Count - 1].Name + " " + minutes);
return minutes;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyCars
{
class Program
{
static void Main(string[] args)
{
CarCaculator carc = new CarCaculator();
int total = 0;
while (true)
{
int days = carc.WinNextCar();
if (days == 0)
break;
total += days;
}
Console.WriteLine("Total Days:" + total / (60 * 24));
Console.ReadLine();
}
public class Car
{
public string Name { get; set; }
public int Price { get; set; }
}
public class CarCaculator
{
#region all cars
private readonly List<Car> _allCars = new List<Car>{ new Car { Name = "奥拓 二手奥拓", Price = 16000},
new Car { Name = "奥拓 奥拓小王子", Price = 20000},
new Car { Name = "夏利 夏利", Price = 32000},
new Car { Name = "奇瑞 奇瑞QQ", Price = 36000},
new Car { Name = "雪佛兰 SPARK乐驰", Price = 45800},
new Car { Name = "吉利 吉利自由舰", Price = 48000},
new Car { Name = "富康 富康", Price = 62000},
new Car { Name = "雨燕 雨燕", Price = 69000},
new Car { Name = "标致 标致206", Price = 78000},
new Car { Name = "雪铁龙 雪铁龙C2", Price = 79000},
new Car { Name = "MG 名爵3SW", Price = 79800},
new Car { Name = "大众 桑塔纳", Price = 80000},
new Car { Name = "大众 POLO", Price = 91000},
new Car { Name = "福田 福田欧马可", Price = 98800},
new Car { Name = "别克 别克凯越", Price = 105000},
new Car { Name = "标致 标致307", Price = 110000},
new Car { Name = "大众 宝来", Price = 116000},
new Car { Name = "起亚 赛拉图", Price = 127800},
new Car { Name = "福特 福特福克斯", Price = 128000},
new Car { Name = "本田 飞度", Price = 129800},
new Car { Name = "冒牌警车 冒牌警车", Price = 130000},
new Car { Name = "丰田 卡罗拉", Price = 132000},
new Car { Name = "大众 速腾", Price = 138000},
new Car { Name = "大众 高尔夫", Price = 139000},
new Car { Name = "本田 本田CIVIC", Price = 140000},
new Car { Name = "日产 骐达", Price = 149800},
new Car { Name = "大众 朗逸", Price = 149800},
new Car { Name = "雪铁龙 新毕加索", Price = 157800},
new Car { Name = "大众 帕萨特", Price = 186000},
new Car { Name = "酷派 现代酷派", Price = 190000},
new Car { Name = "大众 迈腾", Price = 198000},
new Car { Name = "本田 雅阁", Price = 199000},
new Car { Name = "福特 S-MAX", Price = 219800},
new Car { Name = "斯巴鲁 斯巴鲁翼豹", Price = 239800},
new Car { Name = "福特 蒙迪欧-致胜", Price = 239800},
new Car { Name = "本田 本田CRV", Price = 239800},
new Car { Name = "现代 途胜", Price = 241800},
new Car { Name = "大众 甲壳虫", Price = 250000},
new Car { Name = "奥迪 奥迪A4", Price = 280000},
new Car { Name = "哈雷 哈雷摩托", Price = 300000},
new Car { Name = "Mini Copper Mini Cooper", Price = 320000},
new Car { Name = "宝马 宝马320", Price = 330000},
new Car { Name = "切诺基", Price = 420000},
new Car { Name = "JEEP 牧马人", Price = 525000},
new Car { Name = "宝马 宝马Z4", Price = 568000},
new Car { Name = "奥迪 奥迪A6", Price = 620000},
new Car { Name = "奥迪 奥迪TT", Price = 645000},
new Car { Name = "悍马 悍马", Price = 800000},
new Car { Name = "凯迪拉克 凯迪拉克", Price = 878000},
new Car { Name = "宝马 宝马730", Price = 1080000},
new Car { Name = "沃尔沃 沃尔沃XC90", Price = 1138000},
new Car { Name = "奥迪 奥迪Q7", Price = 1232000},
new Car { Name = "路虎 路虎", Price = 1280000},
new Car { Name = "宝马 宝马X5", Price = 1336000},
new Car { Name = "林肯 林肯加长", Price = 1380000},
new Car { Name = "保时捷 保时捷911", Price = 1500000},
new Car { Name = "奔驰 RIMOR奔驰房车", Price = 1500000},
new Car { Name = "保时捷 保时捷卡宴", Price = 1520000},
new Car { Name = "大众 途锐", Price = 1580000},
new Car { Name = "雷克萨斯 雷克萨斯LS600", Price = 1598000},
new Car { Name = "奥迪 奥迪R8", Price = 1599000},
new Car { Name = "玛莎拉蒂", Price = 1790000},
new Car { Name = "奔驰 奔驰S600", Price = 2000000},
new Car { Name = "奔驰 奔驰豪华大巴", Price = 2500000},
new Car { Name = "法拉利 法拉利F430", Price = 3200000},
new Car { Name = "兰博基尼 兰博基尼", Price = 3980000},
new Car { Name = "马自达 马自达", Price = 6178000},
new Car { Name = "迈巴赫 迈巴赫62", Price = 6180000},
new Car { Name = "劳斯莱斯 劳斯莱斯", Price = 6200000},
new Car { Name = "帕加尼 帕加尼", Price = 12990000},
new Car { Name = "宾利 雅致728", Price = 13880000},
new Car { Name = "EB 布加迪威龙", Price = 25000000}};
#endregion
public CarCaculator()
{
_cars = new List<Car>();
_cars.Add(_allCars[0]);
}
private List<Car> _cars = new List<Car>();
public List<Car> Cars
{
get { return _cars; }
}
public bool IsFinished()
{
return _cars.Count == _allCars.Count;
}
public int MinutesPerUnit { get { return 15 * 48; } }
public int WinNextCar()
{
if (IsFinished())
return 0;
int price = _allCars[_cars.Count].Price;
int money = _cars.Count * (MinutesPerUnit * 10);
int minutes = (int)Math.Ceiling(price * 1.0F / money) * MinutesPerUnit;
_cars.Add(_allCars[_cars.Count]);
Console.WriteLine(_cars[_cars.Count - 1].Name + " " + minutes);
return minutes;
}
}
}
}
posted on 2008-09-22 19:14 RandomLife 阅读(415) 评论(3) 编辑 收藏 举报