public string FrequencySort(string s)
    {
        Dictionary <char, CharCount> map = new Dictionary <char, CharCount>();

        foreach (char c in s)
        {
            if (!map.ContainsKey(c))
            {
                map[c] = new CharCount(1, c);
            }
            else
            {
                map[c].Count += 1;
            }
        }
        List <CharCount> list = new List <CharCount>(map.Values);

        list.Sort((x, y) => y.Count.CompareTo(x.Count));
        StringBuilder sb = new StringBuilder();

        foreach (CharCount cc in list)
        {
            for (int i = 0; i < cc.Count; i++)
            {
                sb.Append(cc.Character);
            }
        }
        return(sb.ToString());
    }
        public string FrequencySort2(string s)
        {
            var count = new CharCount[128];
            var list  = new List <CharCount>();

            foreach (char c in s)
            {
                if (count[c] == null)
                {
                    count[c] = new CharCount(c, 1);
                    list.Add(count[c]);
                }
                else
                {
                    count[c].count++;
                }
            }

            var res = new StringBuilder();

            foreach (var item in list.OrderByDescending(i => i.count))
            {
                for (int i = 0; i < item.count; i++)
                {
                    res.Append(item.character);
                }
            }
            return(res.ToString());
        }
        public ActionResult ShipCountData(DataSourceRequest command, CharCount model)
        {
            Guid id;

            if (User.Identity.Name != null && User.Identity.Name != "")
            {
                id = userDb.Users.Where(x => x.UserName == User.Identity.Name).FirstOrDefault().Guild_Id;
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }

            var memberShips = db.MemberShips.Where(x => x.Member.Guild_Id == id);
            var ships       = db.Ships.Where(x => x.Id == x.Id).OrderBy(x => x.Name);
            var gridModel   = new DataSourceResult();

            DataSet ds = new DataSet("Counts");

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SwgohDb"].ConnectionString))
            {
                SqlCommand sqlComm = new SqlCommand("ShipCounts", conn);
                sqlComm.Parameters.AddWithValue("@Guild_Id", id);

                sqlComm.CommandType = CommandType.StoredProcedure;

                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = sqlComm;

                da.Fill(ds);

                gridModel.Data = ds.Tables[0].AsEnumerable().Select(
                    dataRow => new ShipCountModel
                {
                    Id             = dataRow.Field <Guid>("Ship_Id"),
                    Name           = dataRow.Field <string>("Name"),
                    Alignment      = dataRow.Field <string>("Alignment"),
                    OneStarCount   = dataRow.Field <int>("OneStarCount"),
                    TwoStarCount   = dataRow.Field <int>("TwoStarCount"),
                    ThreeStarCount = dataRow.Field <int>("ThreeStarCount"),
                    FourStarCount  = dataRow.Field <int>("FourStarCount"),
                    FiveStarCount  = dataRow.Field <int>("FiveStarCount"),
                    SixStarCount   = dataRow.Field <int>("SixStarCount"),
                    SevenStarCount = dataRow.Field <int>("SevenStarCount"),
                }).AsEnumerable().OrderBy(x => x.Name);
                gridModel.Total = ds.Tables[0].AsEnumerable().Count();
            }
            return(Json(gridModel));
        }
Example #4
0
 public void TestMethod1_UpperCase()
 {
     Assert.AreEqual(4, CharCount.CountUpper("The San Diego Zoo"));
     Assert.AreEqual(3, CharCount.CountUpper("onceUponATime"));
     Assert.AreEqual(2, CharCount.CountUpper("You and Me"));
 }