51
1
using System;
2
using System.ComponentModel.DataAnnotations;
3
4
namespace FindFreePlaceMvcApp
5
{
6
public class ViewModel
7
{
8
[Required]
9
[MinLength(10)]
10
[MaxLength(100)]
11
[Display(Name = "Places")]
12
[RegularExpression(@"([tfTF]+)", ErrorMessage = "Invalid bool array")]
13
public string Places
14
{
15
get;
16
set;
17
}
18
19
[Required]
20
[Display(Name = "IsRotary")]
21
public bool IsRotary
22
{
23
get;
24
set;
114
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
1
@model FindFreePlaceMvcApp.ViewModel
2
@{
3
Layout = null;
4
}
5
6
<!DOCTYPE html>
7
<!-- template from http://getbootstrap.com/getting-started -->
8
9
<html lang="en">
10
<head>
11
<meta charset="utf-8">
12
<meta http-equiv="X-UA-Compatible" content="IE=edge">
13
<meta name="viewport" content="width=device-width, initial-scale=1">
14
<title>Bootstrap 101 Template</title>
15
16
<!-- CSS Includes -->
17
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
18
19
<style type="text/css">
20
21
.field-validation-error {
22
color: #ff0000;
23
}
24
65
1
using System;
2
using System.Web.Http;
3
using System.Web.Mvc;
4
using System.Collections.Generic;
5
6
class Solution
7
{
8
static public int FindFreePlace(bool[] places, bool isRotary, int neededPlaces)
9
{
10
// Insert the code
11
int freeCount = 0;
12
int freeStart = -1;
13
int startCount = 0;
14
for (int here = 0; here < places.Length; ++here)
15
{
16
if (!places[here])
17
{
18
if(freeStart == 0)
19
startCount = freeCount;
20
freeCount = 0;
21
continue;
22
}
23
24
if (freeCount == 0)