/// <summary> /// 获取某一年有多少周 /// </summary> /// <param name="year">年份</param> /// <returns>该年周数</returns> public static int GetWeekAmount(int year) { var end = new DateTime(year, 12, 31); //该年最后一天 var gc = new GregorianCalendar(); return gc.GetWeekOfYear(end, CalendarWeekRule.FirstDay, DayOfWeek.Monday); //该年星期数 }
void BuildLength(int[] childs) { this.length = new byte [freqs.Length]; int numNodes = childs.Length / 2; int numLeafs = (numNodes + 1) / 2; int overflow = 0; for (int i = 0; i < maxLength; i++) { bl_counts[i] = 0; } // First calculate optimal bit lengths int[] lengths = new int[numNodes]; lengths[numNodes - 1] = 0; for (int i = numNodes - 1; i >= 0; i--) { if (childs[2 * i + 1] != -1) { int bitLength = lengths[i] + 1; if (bitLength > maxLength) { bitLength = maxLength; overflow++; } lengths[childs[2 * i]] = lengths[childs[2 * i + 1]] = bitLength; } else { // A leaf node int bitLength = lengths[i]; bl_counts[bitLength - 1]++; this.length[childs[2 * i]] = (byte)lengths[i]; } } // if (DeflaterConstants.DEBUGGING) { // //Console.WriteLine("Tree "+freqs.Length+" lengths:"); // for (int i=0; i < numLeafs; i++) { // //Console.WriteLine("Node "+childs[2*i]+" freq: "+freqs[childs[2*i]] // + " len: "+length[childs[2*i]]); // } // } if (overflow == 0) { return; } int incrBitLen = maxLength - 1; do { // Find the first bit length which could increase: while (bl_counts[--incrBitLen] == 0) { ; } // Move this node one down and remove a corresponding // number of overflow nodes. do { bl_counts[incrBitLen]--; bl_counts[++incrBitLen]++; overflow -= 1 << (maxLength - 1 - incrBitLen); } while (overflow > 0 && incrBitLen < maxLength - 1); } while (overflow > 0); /* We may have overshot above. Move some nodes from maxLength to * maxLength-1 in that case. */ bl_counts[maxLength - 1] += overflow; bl_counts[maxLength - 2] -= overflow; /* Now recompute all bit lengths, scanning in increasing * frequency. It is simpler to reconstruct all lengths instead of * fixing only the wrong ones. This idea is taken from 'ar' * written by Haruhiko Okumura. * * The nodes were inserted with decreasing frequency into the childs * array. */ int nodePtr = 2 * numLeafs; for (int bits = maxLength; bits != 0; bits--) { int n = bl_counts[bits - 1]; while (n > 0) { int childPtr = 2 * childs[nodePtr++]; if (childs[childPtr + 1] == -1) { // We found another leaf length[childs[childPtr]] = (byte)bits; n--; } } } // if (DeflaterConstants.DEBUGGING) { // //Console.WriteLine("*** After overflow elimination. ***"); // for (int i=0; i < numLeafs; i++) { // //Console.WriteLine("Node "+childs[2*i]+" freq: "+freqs[childs[2*i]] // + " len: "+length[childs[2*i]]); // } // } }
protected override Branch GetEntry(int id) { return(Context.Branches.FirstOrDefault(f => f.Id == id)); }
public string UpdateVisibleRegion(Vector3 currentPosition) { bool stateUpdate = false; //TODO: perf optimization to batch draw tile calls into a single drawingsession scope if (currentPosition.X > (currentTopLeftTileColumn + 1) * TILESIZE) // scrolling left, need new items to the right { stateUpdate = true; currentTopLeftTileColumn++; this.currentPosition.X += TILESIZE; for (int row = currentTopLeftTileRow; row < currentTopLeftTileRow + verticalVisibleTileCount + DRAWAHEAD; row++) { for (int column = drawnRightTileColumn + 1; column <= drawnRightTileColumn + 1 + DRAWAHEAD; column++) { DrawTile(row, column); } } drawnRightTileColumn++; } else if (currentPosition.X >= 0 && currentPosition.X < (currentTopLeftTileColumn * TILESIZE)) // scrolling right, need new items to the right { stateUpdate = true; currentTopLeftTileColumn--; this.currentPosition.X -= TILESIZE; for (int row = currentTopLeftTileRow; row < currentTopLeftTileRow + verticalVisibleTileCount + DRAWAHEAD; row++) { for (int column = drawnLeftTileColumn - 1; column >= drawnLeftTileColumn - 1 - DRAWAHEAD; column--) { DrawTile(row, column); } } drawnLeftTileColumn--; } else if (currentPosition.Y > (currentTopLeftTileRow + 1) * TILESIZE) // scrolling down, need new items on bottom { stateUpdate = true; currentTopLeftTileRow++; this.currentPosition.Y += TILESIZE; for (int row = drawnBottomTileRow + 1; row <= drawnBottomTileRow + 1 + DRAWAHEAD; row++) { for (int column = drawnLeftTileColumn; column <= drawnRightTileColumn; column++) { DrawTile(row, column); } } drawnBottomTileRow++; } else if (currentPosition.Y >= 0 && currentPosition.Y < (currentTopLeftTileRow * TILESIZE)) // scrolling up, need new items on top { stateUpdate = true; currentTopLeftTileRow--; this.currentPosition.Y -= TILESIZE; for (int row = drawnTopTileRow - 1; row >= drawnTopTileRow - 1 - DRAWAHEAD; row--) { for (int column = drawnLeftTileColumn; column <= drawnRightTileColumn; column++) { DrawTile(row, column); } } drawnTopTileRow--; } if (stateUpdate) { Trim(); } return($"Left tile:{currentTopLeftTileColumn} Top tile:{currentTopLeftTileRow}"); }
public void BuildTree() { int numSymbols = freqs.Length; /* heap is a priority queue, sorted by frequency, least frequent * nodes first. The heap is a binary tree, with the property, that * the parent node is smaller than both child nodes. This assures * that the smallest node is the first parent. * * The binary tree is encoded in an array: 0 is root node and * the nodes 2*n+1, 2*n+2 are the child nodes of node n. */ int[] heap = new int[numSymbols]; int heapLen = 0; int maxCode = 0; for (int n = 0; n < numSymbols; n++) { int freq = freqs[n]; if (freq != 0) { // Insert n into heap int pos = heapLen++; int ppos; while (pos > 0 && freqs[heap[ppos = (pos - 1) / 2]] > freq) { heap[pos] = heap[ppos]; pos = ppos; } heap[pos] = n; maxCode = n; } } /* We could encode a single literal with 0 bits but then we * don't see the literals. Therefore we force at least two * literals to avoid this case. We don't care about order in * this case, both literals get a 1 bit code. */ while (heapLen < 2) { int node = maxCode < 2 ? ++maxCode : 0; heap[heapLen++] = node; } numCodes = Math.Max(maxCode + 1, minNumCodes); int numLeafs = heapLen; int[] childs = new int[4 * heapLen - 2]; int[] values = new int[2 * heapLen - 1]; int numNodes = numLeafs; for (int i = 0; i < heapLen; i++) { int node = heap[i]; childs[2 * i] = node; childs[2 * i + 1] = -1; values[i] = freqs[node] << 8; heap[i] = i; } /* Construct the Huffman tree by repeatedly combining the least two * frequent nodes. */ do { int first = heap[0]; int last = heap[--heapLen]; // Propagate the hole to the leafs of the heap int ppos = 0; int path = 1; while (path < heapLen) { if (path + 1 < heapLen && values[heap[path]] > values[heap[path + 1]]) { path++; } heap[ppos] = heap[path]; ppos = path; path = path * 2 + 1; } /* Now propagate the last element down along path. Normally * it shouldn't go too deep. */ int lastVal = values[last]; while ((path = ppos) > 0 && values[heap[ppos = (path - 1) / 2]] > lastVal) { heap[path] = heap[ppos]; } heap[path] = last; int second = heap[0]; // Create a new node father of first and second last = numNodes++; childs[2 * last] = first; childs[2 * last + 1] = second; int mindepth = Math.Min(values[first] & 0xff, values[second] & 0xff); values[last] = lastVal = values[first] + values[second] - mindepth + 1; // Again, propagate the hole to the leafs ppos = 0; path = 1; while (path < heapLen) { if (path + 1 < heapLen && values[heap[path]] > values[heap[path + 1]]) { path++; } heap[ppos] = heap[path]; ppos = path; path = ppos * 2 + 1; } // Now propagate the new element down along path while ((path = ppos) > 0 && values[heap[ppos = (path - 1) / 2]] > lastVal) { heap[path] = heap[ppos]; } heap[path] = last; } while (heapLen > 1); if (heap[0] != childs.Length / 2 - 1) { throw new SharpZipBaseException("Heap invariant violated"); } BuildLength(childs); }
/// <summary> /// 文件名(Unicode) /// </summary> /// <param name="attribute"></param> public FileNameAttribute(MainFileTableAttribute attribute) { buffer = attribute.Buffer; startIndex = attribute.DataStartIndex; }
private Rect GetRectForTileRange(int tileStartColumn, int tileStartRow, int numColumns, int numRows) { int x = tileStartColumn * TILESIZE; int y = tileStartRow * TILESIZE; return(new Rect(x, y, numColumns * TILESIZE, numRows * TILESIZE)); }
private void BindMenusList() { StringBuilder StrMenu = new StringBuilder(); DataTable dt = new DataTable(); DataTable dtSubmenu = new DataTable(); dt = clsobj.GetMenuList(); if (dt.Rows.Count > 0) { string PageName = dt.Rows[0]["PageName"].ToString(); StrMenu.Append("<a class='toggleMenu' href='#'></a>"); StrMenu.Append("<ul class='nav'>"); StrMenu.Append("<li class='test' style='background:none;'><a href='../Home.aspx' title='Home'>Home</a></li>"); //for (int i = 0; i < dt.Rows.Count; i++) //{ // clsobj.PageID = Convert.ToInt32(dt.Rows[i]["ID"]); // dtSubmenu = clsobj.GetSubMenuBy_PageID(); // //check if it has submenu // if (dtSubmenu.Rows.Count > 0) // { // StrMenu.Append("<li><a href=#>" + dt.Rows[i]["PageName"] + "</a>");//</li> // StrMenu.Append("<ul>"); // for (int j = 0; j < dtSubmenu.Rows.Count; j++) // { // StrMenu.Append("<li><a href='../StaticPages.aspx?PageID=" + dtSubmenu.Rows[j]["id"] + "' title='" + dtSubmenu.Rows[j]["PageName"] + "'>" + dtSubmenu.Rows[j]["PageName"] + "</a> </li>"); // } // StrMenu.Append("</ul>"); // StrMenu.Append("</li>"); // } // else // { // StrMenu.Append("<li><a href='../StaticPages.aspx?PageID=" + dt.Rows[i]["id"] + "' title='" + dt.Rows[i]["PageName"] + "'>" + dt.Rows[i]["PageName"] + "</a>");//</li> // // } // } //} DataTable exclusive_dt = clsobj.GetExclusiveListing(); StrMenu.Append("<li><a href=#>My Listing</a>");//</li> if (exclusive_dt.Rows.Count > 0) { StrMenu.Append("<ul >"); for (int j = 0; j < exclusive_dt.Rows.Count; j++) { StrMenu.Append("<li><a href='../ExclusiveDetailPage.aspx?Id=" + exclusive_dt.Rows[j]["Id"] + "' title='Home'>" + exclusive_dt.Rows[j]["Title"] + "</a></li>"); } StrMenu.Append("</ul>"); } // StrMenu.Append("<li class='menuu' style='background:none;'><a href='Home_worth.aspx' title='Home Evaluation'>Free Home Evaluation</a></li>"); StrMenu.Append("<li class='test' style='background:none;'><a href='Calculators.aspx' title='Calculators'>Calculators</a></li>"); StrMenu.Append("<li class='test' style='background:none;'><a href='View_Testimonials.aspx' title='Testimonials'>Testimonials</a></li>"); StrMenu.Append("<li>"); StrMenu.Append("<a href='RealEstateNews.aspx' title='Real Estate news'>Real Estate News</a>"); StrMenu.Append("</li>"); StrMenu.Append("<li class='test' style='background:none;'><a href='GallaryPage.aspx' title='Gallary'>Our Models</a></li>"); StrMenu.Append("<li class='test' style='background:none;'><a href='ContactUs.aspx' title='Contact Us'>Contact Us</a></li>"); StrMenu.Append("</ul>"); } dynamicmenus.Text = StrMenu.ToString(); }
public DepositCreatedEvent(int idTransaction, decimal amount, string type, string creationDate, int accountId) { IdTransaction = idTransaction; Amount = amount; Type = type; CreationDate = creationDate; AccountId = accountId; }
public Student UpdateStudent(string id, string nume, int grupa, string email, string prof) { return repo.Update(new Student(id, nume, grupa, email, prof)); }
public Sponsor GetSponsorById(int id) { throw new NotImplementedException(); }
public Student AddStudent(string id, string nume, int grupa, string email, string prof) { return repo.Save(new Student(id, nume, grupa, email, prof)); }
public override void Operation(int extrinsicState) { Console.WriteLine("UnsharedConcreteFlyweight: " + extrinsicState); }
public abstract void Operation(int extrinsicState);
private static void MakeTurn(char[,] gameField, char[,] bombsField, int row, int column) { char bombsCount = GetNearlyBombsCount(bombsField, row, column); bombsField[row, column] = bombsCount; gameField[row, column] = bombsCount; }
public Task StringSetAsync(string key, string value, int timeToLiveInSeconds, AwaitOptions awaitOptions) { return(StringSetAsync(new RedisKeyValue(key, value), timeToLiveInSeconds, awaitOptions)); }
public void calculateTotal() { int box1 = 0, box2 = 0, box31 = 0, box32 = 0, box33 = 0, box4 = 0; try { if (rbSmall.Checked) { int.TryParse(txtSmall.Text, out box1); } if (rbMedium.Checked) { int.TryParse(txtMedium.Text, out box1); } if (rbLarge.Checked) { int.TryParse(txtLarge.Text, out box1); } }catch(Exception e) { MessageBox.Show("Cannot have an empty input!"); } try { if (cbSpices.Checked) { box2 += int.Parse(txtSpices.Text); } if (cbCheese.Checked) { box2 += int.Parse(txtCheese.Text); } if (cbKetchup.Checked) { box2 += int.Parse(txtKetchup.Text); } }catch(Exception e) { MessageBox.Show("Cannot have empty input!"); } try { box31 = int.Parse(txtQuantityCocaCola.Text) * int.Parse(txtPriceCocaCola.Text); box32 = int.Parse(txtQuantityJuice.Text) * int.Parse(txtPriceJuice.Text); box33 = int.Parse(txtQuantityBeer.Text) * int.Parse(txtPriceBeer.Text); } catch(Exception e) {MessageBox.Show("Cannot have empty input!"); } txtTotalPriceCocaCola.Text = Convert.ToString(box31); txtTotalPriceJuice.Text = Convert.ToString(box32); txtTotalPriceBeer.Text = Convert.ToString(box33); if(txtPriceOfTheDesert.Text == "0" && lbDeserts.SelectedIndex != -1) { if(lbDeserts.SelectedItem.ToString().Equals("Fruit pie")) { txtPriceOfTheDesert.Text = "140"; } else if(lbDeserts.SelectedItem.ToString().Equals("Cake")) { txtPriceOfTheDesert.Text = "210"; } else if(lbDeserts.SelectedItem.ToString().Equals("Ice cream")) { txtPriceOfTheDesert.Text = "90"; } } box4 = int.Parse(txtPriceOfTheDesert.Text); txtTotalPrice.Text = Convert.ToString(box1 + box2 + box31 + box32 + box33 + box4); int payed = 0; int.TryParse(txtPayed.Text, out payed); int change = 0; change = int.Parse(txtTotalPrice.Text) - payed; if (payed == 0) txtChange.Text = "0"; else txtChange.Text = Convert.ToString(change); }
private Task StringSetAsync(RedisKeyValue redisKeyValue, int timeToLiveInSeconds, AwaitOptions awaitOptions) { return(StringSetAsync(redisKeyValue, timeToLiveInSeconds, awaitOptions, CancellationToken.None)); }
protected void cmd_save_days_Click(object sender, EventArgs e) { int str_ndias = Convert.ToInt32(txt_days.Text); int str_count; using (bd_tsEntities edm_cadvideos = new bd_tsEntities()) { var i_cadvideos = (from c in edm_cadvideos.inf_caducidad_videos select c).Count(); str_count = i_cadvideos; } if (str_count == 0) { using (var edm_cadvideos = new bd_tsEntities()) { var i_cadvideos = new inf_caducidad_videos { dias_caducidad = str_ndias, id_usuario = guid_fidusuario, id_tribunal = guid_fidcentro, fecha_registro = DateTime.Now }; edm_cadvideos.inf_caducidad_videos.Add(i_cadvideos); edm_cadvideos.SaveChanges(); } using (bd_tsEntities edm_fecha_transf = new bd_tsEntities()) { var ii_fecha_transf = (from u in edm_fecha_transf.inf_caducidad_videos select u).ToList(); if (ii_fecha_transf.Count == 0) { } else { using (var insert_user = new bd_tsEntities()) { var items_user = new inf_caducidad_videos_dep { id_usuario = guid_fidusuario, id_caducidad_videos = ii_fecha_transf[0].id_caducidad_videos, id_tipo_accion = id_accion(), fecha_registro = DateTime.Now, }; insert_user.inf_caducidad_videos_dep.Add(items_user); insert_user.SaveChanges(); } } } txt_days.Text = ""; using (bd_tsEntities edm_cadvideos = new bd_tsEntities()) { var i_cadvideos = (from u in edm_cadvideos.inf_caducidad_videos where u.dias_caducidad == str_ndias select new { u.id_caducidad_videos, u.dias_caducidad, u.fecha_registro }).ToList(); gv_dayvideosf.DataSource = i_cadvideos; gv_dayvideosf.DataBind(); gv_dayvideosf.Visible = true; } rb_add_dayvideos.Visible = false; lblModalTitle.Text = "transcript"; lblModalBody.Text = "Dias de respaldo, agregado con éxito"; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal();", true); upModal.Update(); } else { foreach (GridViewRow row in gv_dayvideos.Rows) { if (row.RowType == DataControlRowType.DataRow) { CheckBox chkRow = (row.Cells[0].FindControl("chk_select") as CheckBox); if (chkRow.Checked) { int str_code = Convert.ToInt32(row.Cells[1].Text); using (var edm_cadvideos = new bd_tsEntities()) { var i_cadvideos = (from c in edm_cadvideos.inf_caducidad_videos where c.id_caducidad_videos == str_code select c).FirstOrDefault(); i_cadvideos.dias_caducidad = str_ndias; edm_cadvideos.SaveChanges(); } using (bd_tsEntities edm_fecha_transf = new bd_tsEntities()) { var ii_fecha_transf = (from u in edm_fecha_transf.inf_caducidad_videos select u).ToList(); if (ii_fecha_transf.Count == 0) { } else { using (var insert_user = new bd_tsEntities()) { var items_user = new inf_caducidad_videos_dep { id_usuario = guid_fidusuario, id_caducidad_videos = ii_fecha_transf[0].id_caducidad_videos, id_tipo_accion = id_accion(), fecha_registro = DateTime.Now, }; insert_user.inf_caducidad_videos_dep.Add(items_user); insert_user.SaveChanges(); } } } txt_days.Text = ""; ; lblModalTitle.Text = "transcript"; lblModalBody.Text = "Dias de respaldo, actualizado con éxito"; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal();", true); upModal.Update(); using (bd_tsEntities edm_cadvideos = new bd_tsEntities()) { var i_cadvideos = (from u in edm_cadvideos.inf_caducidad_videos where u.id_caducidad_videos == str_code select new { u.id_caducidad_videos, u.dias_caducidad, u.fecha_registro }).ToList(); gv_dayvideos.DataSource = i_cadvideos; gv_dayvideos.DataBind(); gv_dayvideos.Visible = true; } } } } } }
public Task StringSetAsync(string key, string value, int timeToLiveInSeconds, AwaitOptions awaitOptions, CancellationToken cancellationToken) { return(StringSetAsync(new RedisKeyValue(key, value), awaitOptions, cancellationToken)); }
private void DrawTile(int row, int column) { this.currentRenderer.DrawTile(GetRectForTile(row, column), row, column); //index's are 0 based }
public Frog(string name, int age, string gender) : base(name, age, gender) { }
private void btnCollectDirectory_Click(object sender, EventArgs e) { //Get the DictFile string[] reads = File.ReadAllLines(tbPicPath.Text + "\\Translate.txt"); Dictionary <string, string> mapName = new Dictionary <string, string>(); foreach (string r in reads) { string[] ss = r.Split('|'); mapName[ss[0]] = ss[1]; } DirectoryInfo info = new DirectoryInfo(tbPicPath.Text + "_processed"); DirectoryInfo[] dirs = info.GetDirectories(); Dictionary <int, PicCategory> mapDir = new Dictionary <int, PicCategory>(); foreach (DirectoryInfo inf in dirs) { string[] ss = inf.Name.Split('_'); PicCategory c = new PicCategory(); c.ID = Int32.Parse(ss[1]); c.SortID = Int32.Parse(ss[2]); c.EName = ss[0]; if (mapName.ContainsKey(ss[0])) { c.CName = mapName[ss[0]]; } else { c.CName = c.EName; } c.SrcPath = inf.FullName; mapDir[c.SortID] = c; } string sNewPath = tbPicPath.Text + "_Output"; Directory.CreateDirectory(sNewPath); string sJson = "["; //Change the order! int iMaxSortID = mapDir.Count; for (int iCur = 0; iCur < iMaxSortID; iCur++) { PicCategory c = mapDir[iCur]; string sCatPath = sNewPath + "\\" + c.ID; Directory.CreateDirectory(sCatPath); FileInfo[] fileNames = new DirectoryInfo(c.SrcPath).GetFiles(); int iCnt = (fileNames.Length - 1) / 2; sJson += "{c:" + c.ID + ",n:'" + c.CName.Replace("\'", "\\\'") + "',max:" + iCnt.ToString() + "},"; foreach (FileInfo fInfo in fileNames) { if (fInfo.Name == "category.gif") { Bitmap bm = Bitmap.FromFile(fInfo.FullName) as Bitmap; bm.Save(sCatPath + "\\category.png", ImageFormat.Png); } else { fInfo.CopyTo(sCatPath + "\\" + fInfo.Name); } } } sJson = sJson.Substring(0, sJson.Length - 1); sJson += "]"; File.WriteAllText(sNewPath + "\\Category.txt", sJson); }
public static IWebElement ScrollTo(this IWebElement element, int x, int y) { var driver = (element as IWrapsDriver).WrappedDriver; (driver as IJavaScriptExecutor).ExecuteScript($"arguments[0].scrollTo({x},{y});", element); return element; }
/// <summary> /// Write tree values /// </summary> /// <param name="blTree">Tree to write</param> public void WriteTree(Tree blTree) { int max_count; // max repeat count int min_count; // min repeat count int count; // repeat count of the current code int curlen = -1; // length of current code int i = 0; while (i < numCodes) { count = 1; int nextlen = length[i]; if (nextlen == 0) { max_count = 138; min_count = 3; } else { max_count = 6; min_count = 3; if (curlen != nextlen) { blTree.WriteSymbol(nextlen); count = 0; } } curlen = nextlen; i++; while (i < numCodes && curlen == length[i]) { i++; if (++count >= max_count) { break; } } if (count < min_count) { while (count-- > 0) { blTree.WriteSymbol(curlen); } } else if (curlen != 0) { blTree.WriteSymbol(REP_3_6); dh.pending.WriteBits(count - 3, 2); } else if (count <= 10) { blTree.WriteSymbol(REP_3_10); dh.pending.WriteBits(count - 3, 3); } else { blTree.WriteSymbol(REP_11_138); dh.pending.WriteBits(count - 11, 7); } } }
private static char GetNearlyBombsCount(char[,] field, int row, int column) { int bombsCount = 0; int rowsCount = field.GetLength(0); int colsCount = field.GetLength(1); if (row - 1 >= 0) { if (field[row - 1, column] == '*') { bombsCount++; } } if (row + 1 < rowsCount) { if (field[row + 1, column] == '*') { bombsCount++; } } if (column - 1 >= 0) { if (field[row, column - 1] == '*') { bombsCount++; } } if (column + 1 < colsCount) { if (field[row, column + 1] == '*') { bombsCount++; } } if ((row - 1 >= 0) && (column - 1 >= 0)) { if (field[row - 1, column - 1] == '*') { bombsCount++; } } if ((row - 1 >= 0) && (column + 1 < colsCount)) { if (field[row - 1, column + 1] == '*') { bombsCount++; } } if ((row + 1 < rowsCount) && (column - 1 >= 0)) { if (field[row + 1, column - 1] == '*') { bombsCount++; } } if ((row + 1 < rowsCount) && (column + 1 < colsCount)) { if (field[row + 1, column + 1] == '*') { bombsCount++; } } return char.Parse(bombsCount.ToString()); }
/// <summary> /// Flush block to output with compression /// </summary> /// <param name="stored">Data to flush</param> /// <param name="storedOffset">Index of first byte to flush</param> /// <param name="storedLength">Count of bytes to flush</param> /// <param name="lastBlock">True if this is the last block</param> public void FlushBlock(byte[] stored, int storedOffset, int storedLength, bool lastBlock) { literalTree.freqs[EOF_SYMBOL]++; // Build trees literalTree.BuildTree(); distTree.BuildTree(); // Calculate bitlen frequency literalTree.CalcBLFreq(blTree); distTree.CalcBLFreq(blTree); // Build bitlen tree blTree.BuildTree(); int blTreeCodes = 4; for (int i = 18; i > blTreeCodes; i--) { if (blTree.length[BL_ORDER[i]] > 0) { blTreeCodes = i + 1; } } int opt_len = 14 + blTreeCodes * 3 + blTree.GetEncodedLength() + literalTree.GetEncodedLength() + distTree.GetEncodedLength() + extra_bits; int static_len = extra_bits; for (int i = 0; i < LITERAL_NUM; i++) { static_len += literalTree.freqs[i] * staticLLength[i]; } for (int i = 0; i < DIST_NUM; i++) { static_len += distTree.freqs[i] * staticDLength[i]; } if (opt_len >= static_len) { // Force static trees opt_len = static_len; } if (storedOffset >= 0 && storedLength + 4 < opt_len >> 3) { // Store Block // if (DeflaterConstants.DEBUGGING) { // //Console.WriteLine("Storing, since " + storedLength + " < " + opt_len // + " <= " + static_len); // } FlushStoredBlock(stored, storedOffset, storedLength, lastBlock); } else if (opt_len == static_len) { // Encode with static tree pending.WriteBits((DeflaterConstants.STATIC_TREES << 1) + (lastBlock ? 1 : 0), 3); literalTree.SetStaticCodes(staticLCodes, staticLLength); distTree.SetStaticCodes(staticDCodes, staticDLength); CompressBlock(); Reset(); } else { // Encode with dynamic tree pending.WriteBits((DeflaterConstants.DYN_TREES << 1) + (lastBlock ? 1 : 0), 3); SendAllTrees(blTreeCodes); CompressBlock(); Reset(); } }
private static void Main(string[] args) { const int MAX_MOVES = 35; char[,] gameField = CreateGameField(); char[,] bombsField = CreateBombsField(); int counter = 0; bool hasBombBlown = false; List<Rating> bestPlayers = new List<Rating>(6); int row = 0; int col = 0; bool firstFlag = true; bool secondFlag = false; string command = String.Empty; do { if (firstFlag) { Console.WriteLine( "Hajde da igraem na “Mini4KI”. Probvaj si kasmeta da otkriesh poleteta bez mini4ki." + " Komanda 'top' pokazva klasiraneto, 'restart' po4va nova igra, 'exit' izliza i hajde 4ao!"); PrintField(gameField); firstFlag = false; } Console.Write("Daj red i kolona : "); command = Console.ReadLine().Trim(); if (command.Length >= 3) { if (int.TryParse(command[0].ToString(), out row) && int.TryParse(command[2].ToString(), out col) && row <= gameField.GetLength(0) && col <= gameField.GetLength(1)) { command = "turn"; } } switch (command) { case "top": PrintChart(bestPlayers); break; case "restart": gameField = CreateGameField(); bombsField = CreateBombsField(); PrintField(gameField); hasBombBlown = false; firstFlag = false; break; case "exit": Console.WriteLine("4a0, 4a0, 4a0!"); break; case "turn": if (bombsField[row, col] != '*') { if (bombsField[row, col] == '-') { MakeTurn(gameField, bombsField, row, col); counter++; } if (MAX_MOVES == counter) { secondFlag = true; } else { PrintField(gameField); } } else { hasBombBlown = true; } break; default: Console.WriteLine("\nGreshka! nevalidna Komanda\n"); break; } if (hasBombBlown) { PrintField(bombsField); Console.Write("\nHrrrrrr! Umria gerojski s {0} to4ki. " + "Daj si niknejm: ", counter); string nickName = Console.ReadLine(); var playerRating = new Rating(nickName, counter); if (bestPlayers.Count < 5) { bestPlayers.Add(playerRating); } else { for (int i = 0; i < bestPlayers.Count; i++) { if (bestPlayers[i].Score < playerRating.Score) { bestPlayers.Insert(i, playerRating); bestPlayers.RemoveAt(bestPlayers.Count - 1); break; } } } bestPlayers.Sort((rating1, rating2) => rating2.PlayerName.CompareTo(rating1.PlayerName)); bestPlayers.Sort((rating1, rating2) => rating2.Score.CompareTo(rating1.Score)); PrintChart(bestPlayers); gameField = CreateGameField(); bombsField = CreateBombsField(); counter = 0; hasBombBlown = false; firstFlag = true; } if (secondFlag) { Console.WriteLine("\nBRAVOOOS! Otvri 35 kletki bez kapka kryv."); PrintField(bombsField); Console.WriteLine("Daj si imeto, batka: "); string nickName = Console.ReadLine(); var rating = new Rating(nickName, counter); bestPlayers.Add(rating); PrintChart(bestPlayers); gameField = CreateGameField(); bombsField = CreateBombsField(); counter = 0; secondFlag = false; firstFlag = true; } } while (command != "exit"); Console.WriteLine("Made in Bulgaria - Uauahahahahaha!"); Console.WriteLine("AREEEEEEeeeeeee."); Console.Read(); }
public BoxWithMaxWeight(int capacity) { this.capacity = capacity; this.list = new List <Item>(); this.boxedItemsTotal = 0; }
/** * Draws the labels for the different regions on the DNA strand */ private void drawDNARegions(Graphics g) { SolidBrush brush; SolidBrush textBrush = new SolidBrush(Color.FromArgb(255, 50, 50, 50)); Control control; Font labels = new Font("Calibri", (float)11.5, FontStyle.Bold); PointF textLocation; int alphaValue = 190; // Proximal promotor brush = new SolidBrush(Color.FromArgb(alphaValue, Color.DarkSeaGreen)); // RGB(143, 188, 143) control = this.lblPromotorMark; g.FillRectangle(brush, control.Location.X, control.Location.Y, control.Width, control.Height); textLocation = new PointF(control.Location.X + control.Width / 10, control.Location.Y + control.Height / 3); g.DrawString("Близок промотор", labels, textBrush, textLocation); // TATA box brush = new SolidBrush(Color.FromArgb(alphaValue, 255, 192, 255)); control = this.lblTATAMark; g.FillRectangle(brush, control.Location.X, control.Location.Y, control.Width, control.Height); textLocation = new PointF(control.Location.X + control.Width / 12, control.Location.Y + control.Height / 3); g.DrawString("TATA", labels, textBrush, textLocation); // Transcription Start Site (TSS) brush = new SolidBrush(Color.FromArgb(alphaValue, 192, 255, 192)); control = this.lblTSSMark; g.FillRectangle(brush, control.Location.X, control.Location.Y, control.Width, control.Height); textLocation = new PointF(control.Location.X + control.Width / 10, control.Location.Y + control.Height / 3); g.DrawString("TSS", labels, textBrush, textLocation); // Untranslated region 5' brush = new SolidBrush(Color.FromArgb(alphaValue, 255, 192, 128)); control = this.lblUTR5Mark; g.FillRectangle(brush, control.Location.X, control.Location.Y, control.Width, control.Height); textLocation = new PointF(control.Location.X + control.Width / 4, control.Location.Y + control.Height / 3); g.DrawString("5' UTR", labels, textBrush, textLocation); // Exon 1 brush = new SolidBrush(Color.FromArgb(alphaValue, 192, 192, 255)); control = this.lblExon1Mark; g.FillRectangle(brush, control.Location.X, control.Location.Y, control.Width, control.Height); textLocation = new PointF(control.Location.X + control.Width / 5, control.Location.Y + control.Height / 3); g.DrawString("Егзон 1", labels, textBrush, textLocation); // Intron 1 brush = new SolidBrush(Color.FromArgb(alphaValue, 255, 128, 128)); control = this.lblIntron1Mark; g.FillRectangle(brush, control.Location.X, control.Location.Y, control.Width, control.Height); textLocation = new PointF(control.Location.X + control.Width / 5, control.Location.Y + control.Height / 3); g.DrawString("Интрон 1", labels, textBrush, textLocation); // Exon 2 brush = new SolidBrush(Color.FromArgb(alphaValue, 192, 192, 255)); control = this.lblExon2Mark; g.FillRectangle(brush, control.Location.X, control.Location.Y, control.Width, control.Height); textLocation = new PointF(control.Location.X + control.Width / 12, control.Location.Y + control.Height / 3); g.DrawString("Егзон 2", labels, textBrush, textLocation); // Untranslated region 3' brush = new SolidBrush(Color.FromArgb(alphaValue, 255, 192, 128)); control = this.lblUTR3Mark; g.FillRectangle(brush, control.Location.X, control.Location.Y, control.Width, control.Height); textLocation = new PointF(control.Location.X + control.Width / 4, control.Location.Y + control.Height / 3); g.DrawString("3' UTR", labels, textBrush, textLocation); }