示例#1
0
 /// <summary>
 /// Creates hashtable of empty elements.
 /// </summary>
 /// <param name="hashsize"></param>
 public HashTable(int hashsize)
 {
     table = new List[hashsize];
     for (int i = 0; i < hashsize; ++i)
         table[i] = new List();
     HashSize = hashsize;
     this.countHash = this.CalculateHash;
 }
示例#2
0
 /// <summary>
 /// Creates new hashtable of empty elements, takes a function for the hash table.
 /// </summary>
 /// <param name="hashsize"></param>
 public HashTable(int hashsize, HashFunction CountHash)
 {
     table = new List[hashsize];
     for (int i = 0; i < hashsize; ++i)
         table[i] = new List();
     HashSize = hashsize;
     this.countHash = CountHash;
 }
示例#3
0
 // takes list of int elements, start value and function, returns new list
 public static int Fold(List<int> list, int start, Func<int, int, int> function)
 {
     int result = start;
     for (int i = 0; i < list.Count; ++i)
     {
         result = function(result, list[i]);
     }
     return result;
 }
示例#4
0
        static void Main(string[] args)
        {
            string[] arr = Console.ReadLine().Split().ToArray();
            List<string> list=new List<string>();
            list.AddRange(arr);
            double output = 0;
            if(arr.Contains("*")||arr.Contains("/"))
            {
                for(int i=1;i<list.Count;i++)
                {
                    if(list[i]=="*")
                    {
                        list[i-1]=(double.Parse(list[i-1])*double.Parse(list[i+1])).ToString();
                        list.RemoveRange(i, 2);
                        list.Add("0");
                        list.Add("0");
                        i = 1;
                    }
                    if (list[i] == "/")
                    {
                        list[i-1] = (double.Parse(list[i - 1]) / double.Parse(list[i + 1])).ToString();
                        list.RemoveRange(i, 2);
                        list.Add("0");
                        list.Add("0");
                        i = 1;
                    }

                }

            }
            for (int i = 1; i < list.Count; i++)
            {
                if (list[i-1] == "+")
                {
                    list[i-1] = (double.Parse(list[i - 1]) + double.Parse(list[i + 1])).ToString();
                    list.RemoveRange(i, 2);
                    list.Add("0");
                    list.Add("0");
                    i = 1;
                }
                if (list[i-1] == "-")
                {
                    list[i] = (double.Parse(list[i - 1]) - double.Parse(list[i + 1])).ToString();
                    list.RemoveRange(i, 2);
                    list.Add("0");
                    list.Add("0");
                    i = 1;
                }
            }
            Console.WriteLine(list[0]);
        }
示例#5
0
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            Regex regex = new Regex(@"(?<=\bdouble\s)(\w+)");
            MatchCollection doubles = regex.Matches(input);
            Regex regexint = new Regex(@"(?<=\bint\s)(\w+)");
            MatchCollection ints = regexint.Matches(input);

            var integers=new List<string>();
            var doublers=new List<string>();

            while (input != "//END_OF_CODE")
            {

                doubles = regex.Matches(input);
                ints = regexint.Matches(input);

                foreach (Match p in doubles)
                {
                    doublers.Add(p.ToString());
                }
                foreach (Match q in ints)
                {
                    integers.Add(q.ToString());
                }
                input = Console.ReadLine();
            }
            doublers.Sort();
            integers.Sort();
            if (doublers.Count==0&&integers.Count==0)
            {
                Console.WriteLine("Doubles: None");
                Console.WriteLine("Ints: None");
            }
            else if(doublers.Count==0)
            {
                Console.WriteLine("Doubles: None");
                Console.WriteLine("Ints: " + string.Join(", ", integers));
            }
            else if(integers.Count==0)
            {
                Console.WriteLine("Ints: None");
                Console.WriteLine("Doubles: "+string.Join(", ",doublers));
            }
            else
            {
             Console.WriteLine("Doubles: "+string.Join(", ",doublers));
             Console.WriteLine("Ints: " + string.Join(", ", integers));
            }
        }