c#
Asp.Net MVC Calendar Helper
Recently while working on a project with Asp.Net MVC 3 there was a need for a small calendar similar to the asp.net calendar control. After some searching I decided that the easiest method to get this done would be to write a Html Helper. Below is the code that seems to work nicely. This works even if the browser does not support javascript. For added functionality you could add an extra parameter to show highlighted dates or extend it to fill a page and add content to the cells.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Web; using System.Web.Mvc; namespace AntiYes.Helpers { public static class CalendarExtensions { public static IHtmlString Calendar(this HtmlHelper helper, DateTime dateToShow) { DateTimeFormatInfo cinfo = DateTimeFormatInfo.CurrentInfo; StringBuilder sb = new StringBuilder(); DateTime date = new DateTime(dateToShow.Year, dateToShow.Month, 1); int emptyCells = ((int)date.DayOfWeek + 7 - (int)cinfo.FirstDayOfWeek) % 7; int days = DateTime.DaysInMonth(dateToShow.Year, dateToShow.Month); sb.Append("<table class='cal'><tr><th colspan='7'>" + cinfo.MonthNames[date.Month - 1] + " " + dateToShow.Year + "</th></tr>"); for (int i = 0; i < ((days + emptyCells) > 35 ? 42 : 35); i++) { if (i % 7 == 0) { if (i > 0) sb.Append("</tr>"); sb.Append("<tr>"); } if (i < emptyCells || i >= emptyCells + days) { sb.Append("<td class='cal-empty'> </td>"); } else { sb.Append("<td class='cal-day'>" + date.Day + "</td>"); date = date.AddDays(1); } } sb.Append("</tr></table>"); return helper.Raw(sb.ToString()); } } } |
29. Hash it! - Solution
After going back and forth over this code for it seems like an eternity (about an hour) I finally got an accepted solution. The problem turned out to be a small typo.
Here it is, my solution to https://www.spoj.pl/problems/HASHIT/ in C#.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | using System; using System.Text; namespace HASHIT { class MainClass { public static void Main (string[] args) { int t = Convert.ToInt32 (System.Console.ReadLine ()); for (int i = 0; i < t; i++) { string[] table = new string[101]; int n = Convert.ToInt32 (System.Console.ReadLine ()); for (int i2 = 0; i2 < n; i2++) { string line = System.Console.ReadLine (); string op = line.Substring (0, 3); string key = line.Substring (4); int ix = FindKey (table, key); if (op == "ADD") { if (ix == -1) { ix = FindNextOpenAddress (table, Hash (key)); if (ix >= 0) { table[ix] = key; } } } else { if (ix >= 0) { table[ix] = string.Empty; } } } StringBuilder sb = new StringBuilder (); int count = 0; for (int j = 0; j < 101; j++) { if (!string.IsNullOrEmpty (table[j])) { count++; sb.AppendLine (j + ":" + table[j]); } } Console.WriteLine (count); Console.Write (sb.ToString ()); } } public static int Hash (string key) { int ret = 0; ret = h (key) % 101; return ret; } public static int h (string key) { int ret = 0; int cnt = key.Length; for (int i = 0; i < cnt; i++) { ret += (int)key[i] * (i + 1); } return ret * 19; } public static int FindKey (string[] table, string key) { int ix = Hash (key); if (table[ix] == key) return ix; for (int j = 1; j < 20; j++) { int newix = (ix + j * j + 23 * j) % 101; if (table[newix] == key) { return newix; } } return -1; } public static int FindNextOpenAddress (string[] table, int ix) { if (string.IsNullOrEmpty (table[ix])) return ix; for (int j = 1; j < 20; j++) { int newix = (ix + j * j + 23 * j) % 101; if (string.IsNullOrEmpty (table[newix])) { return newix; } } return -1; } } } |
Stir Trek 2: Iron Man Edition

Stir Trek is an opportunity to learn about the newest advances in web and mobile development. There will be 20 sessions, in four tracks, so you’ll be able to pick the content that interests you the most. In addition, the day will include lunch, a raffle with some significant prizes, and a private screening of the new IronMan 2 movie, which opens in theaters the day of this event.
Visit http://www.stirtrek.com/ for more information.
Central Ohio Day of .NET 2010
The Central Ohio Day of .NET is a joint venture between the Dayton .NET Developers Group, Central Ohio .NET Developers Group, Cincinnati SQL Server Users Group and the Cincinnati .NET Users Group. The event originally was called the Cincinnati-Dayton Area Code camp and ran in 2006 and 2007 under that name. With the inclusion of the Columbus And CincySQL group the event has been renamed to the Central Ohio Day of .NET. The event is a FREE day of technology discussions devoted to helping the local development community grow. Please check back often for more information about Day of .NET events.
Day of .NET events are a series of mini-conferences organized by developers for developers. You can find out more about Day of .NET events, including seeing upcoming events, on the series website at http://www.dodn.org.
Central Ohio Day of .NET 2010!
The Cincinnati .Net Users Group, Central Ohio .NET Developers Group, Dayton .Net Developers Group and Cincinnati SQL Users Group will be hosting this year's Central Ohio Day of .NET on June 5th, 2010. The event will be held at the Roberts Centre in Wilmington, OH (off exit 50 on I-71).
899. Ws Cipher
Weird Wally's Wireless Widgets, Inc. manufactures an eclectic assortment of small, wireless, network capable devices, ranging from dog collars, to pencils, to fishing bobbers. All these devices have very small memories. Encryption algorithms like Rijndael, the candidate for the Advanced Encryption Standard (AES) are demonstrably secure but they don't fit in such a tiny memory. In order to provide some security for transmissions to and from the devices, WWWW uses the following algorithm, which you are to implement.
Encrypting a message requires three integer keys, k1, k2, and k3. The letters [a-i] form one group, [j-r] a second group, and everything else ([s-z] and underscore) the third group. Within each group the letters are rotated left by ki positions in the message. Each group is rotated independently of the other two. Decrypting the message means doing a right rotation by ki positions within each group.
Consider the message the_quick_brown_fox encrypted with ki values of 2, 3 and 1. The encrypted string is _icuo_bfnwhoq_kxert. The figure below shows the decrypting right rotations for one character in each of the three character groups.

Looking at all the letters in the group [a-i] we see {i,c,b,f,h,e} appear at positions {2,3,7,8,11,17} within the encrypted message. After a right rotation of k1=2, these positions contain the letters {h,e,i,c,b,f}. The table below shows the intermediate strings that come from doing all the rotations in the first group, then all rotations in the second group, then all the rotations in the third group. Rotating letters in one group will not change any letters in any of the other groups.
| [a-i], k1= 2 | [j-r], k2= 3 | [s-z] and _, k3= 1 | |
|---|---|---|---|
| Encrypted: | _icuo_bfnwhoq_kxert | _heuo_icnwboq_kxfrt | _heuq_ickwbro_nxfot |
| Decrypted: | _heuo_icnwboq_kxfrt | _heuq_ickwbro_nxfot | the_quick_brown_fox |
| Changes: | ^^ ^^ ^ ^ | ^ ^ ^^ ^ ^ | ^ ^ ^ ^ ^ ^ ^ |
All input strings contain only lowercase letters and underscores(_). Each string will be at most 80 characters long. The ki are all positive integers in the range 1-100.
Input consists of information for one or more encrypted messages. Each problem begins with one line containing k1, k2, and k3 followed by a line containing the encrypted message. The end of the input is signalled by a line with all key values of 0.
For each encrypted message, the output is a single line containing the decrypted string.
Input: 2 3 1 _icuo_bfnwhoq_kxert 1 1 1 bcalmkyzx 3 7 4 wcb_mxfep_dorul_eov_qtkrhe_ozany_dgtoh_u_eji 2 4 3 cjvdksaltbmu 0 0 0
Output: the_quick_brown_fox abcklmxyz the_quick_brown_fox_jumped_over_the_lazy_dog ajsbktcludmv
| Added by: | Wanderley Guimarães |
| Date: | 2006-06-09 |
| Time limit: | 1s |
| Source limit: | 50000B |
| Languages: | All except: ERL TECS JS |
| Resource: | ACM Mid Central Regionals 2001 |
My Solution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | using System; using System.Collections.Generic; namespace www.spoj.pl._899_WSCIPHER { class Program { static void Main(string[] args) { while (true) { string line = Console.In.ReadLine(); string[] nums = line.Split(new char[] { ' ' }); if (nums.Length == 3) { int k1 = 0; int.TryParse(nums[0], out k1); int k2 = 0; int.TryParse(nums[1], out k2); int k3 = 0; int.TryParse(nums[2], out k3); if (k1 == 0 && k2 == 0 && k3 == 0) break; string ciphertext = Console.In.ReadLine(); CipherGroup Group1 = new CipherGroup(k1); CipherGroup Group2 = new CipherGroup(k2); CipherGroup Group3 = new CipherGroup(k3); int len = ciphertext.Length; for (int i = 0; i < len; i++) { char c = ciphertext[i]; if (c >= 'a' && c <= 'i') { Group1.Add(c, i); } else if (c >= 'j' && c <= 'r') { Group2.Add(c, i); } else { Group3.Add(c, i); } } Group1.Rotate(); Group2.Rotate(); Group3.Rotate(); string[] letters = new string[len]; Group1.AddToArray(letters); Group2.AddToArray(letters); Group3.AddToArray(letters); Console.WriteLine(string.Join("", letters)); } } } } public class CipherGroup { public int k { get; set; } public List<char> Letters { get; set; } public List<int> Positions { get; set; } public CipherGroup(int k1) { k = k1; Letters = new List<char>(); Positions = new List<int>(); } public void Add(char c, int p) { Letters.Add(c); Positions.Add(p); } public void Rotate() { int len = Letters.Count; if (len == 0) return; for (int i = 0; i < k; i++) { Letters.Insert(0, Letters[len - 1]); Letters.RemoveAt(len); } } public void AddToArray(string[] letters) { int len = Letters.Count; for (int i = 0; i < len; i++) { letters[Positions[i]] = Letters[i].ToString(); } } } } |
