private static void F1()
        {
            FileStream fs = new FileStream("input.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            StreamReader sr = new StreamReader(fs);
            string line = sr.ReadLine();
            
            /// Записываем все ответы последующих действий в новый текстовый файл
            using (StreamWriter outF = new StreamWriter("answer.txt")) 
         
            {
                string[] arr = line.Split(' '); /// Массив для разделённых char
                var b = new List<int>(); /// Первая коллекция для чисел формата int
                var c = new List<int>(); /// Вторая коллекция для простых чисел

                for (int j = 0; j < arr.Length; ++j)
                {
                    b.Add(int.Parse(arr[j]));
                    if (IsPrime(b[j]) == true)
                    {
                        c.Add(b[j]);
                    }
                }
                int min = c[0]; /// Задаем минимальное значение первой ячейке коллекции простых чисел
                foreach (int i in c)
                {
                    if (i < min)
                    {
                        min = i;
                    }
                }
                Console.WriteLine("Min prime number = " + min); /// Вывести ответ. Все ответы записались в новом текстовом файле
            }
        }
Ejemplo n.º 2
0
 public HashTable()
 {
     list = new List[n];
     for (int i = 0; i < n; ++i)
     {
         list[i] = new List();
     }
 }
Ejemplo n.º 3
0
 public static int FoldFunction(List<int> list, int initialValue, Func<int, int, int> function)
 {
     int result = initialValue;
     foreach (int element in list)
     {
         result = function(result, element);
     }
     return result;
 }
Ejemplo n.º 4
0
 public static int FoldFunc(List<int> list, int acc, FoldDel f)
 {
     int result = acc;
     foreach (int i in list)
     {
         result = f(result, i);
     }
     return result;
 }
 static void Main(string[] args)
 {
     int n = int.Parse(Console.ReadLine());
     int m = int.Parse(Console.ReadLine());
     List<int> size =new List<int>();
     for (int i = 0; i < m; i++)
     {
         size.Add(int.Parse(Console.ReadLine()));
     }
     //int average = 0;
     //for (int i = 0; i < size.Length; i++)
     //{
     //    average += size[i];
     //}
     //average /= m;
     Console.WriteLine(500);
 }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            string input = "";
            var doubles = new Dictionary<int,List<string>>();
            var ints = new Dictionary<int, List<string>>();
            var list = new List<string>();
            int scopeNum = 0;
            int leftbracket = 0;
            int rightbracket = 0;
            bool repeatFlag = false;
            var resultList = new List<string>();

            while (input != "//END_OF_CODE")
            {
                input = Console.ReadLine();
                list = input.Split(' ').Where(s => !string.IsNullOrWhiteSpace(s)).ToList();
                if (list.Count > 0)
                {
                    if (list[0] == "private" || list[0] == "public"|| list[0] == "static" || list[0] == "class" || list[0] == "void" || list[0] == "if"|| list[0] == "else if" || list[0] == "else")
                    {
                        leftbracket = 0;
                        rightbracket = 0;
                    }
                    else if (list[0] == "{")
                    {
                        leftbracket++;
                    }
                    else if (list[0] == "}")
                    {
                        rightbracket++;
                    }

                    if (leftbracket != 0 && rightbracket == leftbracket)
                    {
                        scopeNum++;
                    }

                    //doubles
                    Regex regex = new Regex(@"(?<=double\s)\b.+?\b");
                    Match match = regex.Match(input);

                    if (doubles.ContainsKey(scopeNum))
                    {
                        foreach (var item in doubles[scopeNum])
                        {
                            if (match.Success && item == match.Value)
                            {
                                repeatFlag = true;
                                break;
                            }
                        }

                        if (!repeatFlag)
                        {
                            doubles[scopeNum].Add(match.Value);
                        }
                    }
                    else
                    {
                        list = new List<string>();
                        doubles.Add(scopeNum, list);
                        doubles[scopeNum].Add(match.Value);
                    }

                    //ints
                    regex = new Regex(@"(?<=int\s)\b.+?\b");
                    match = regex.Match(input);

                    if (ints.ContainsKey(scopeNum))
                    {
                        foreach (var item in ints[scopeNum])
                        {
                            if (match.Success && item == match.Value)
                            {
                                repeatFlag = true;
                                break;
                            }
                        }

                        if (!repeatFlag)
                        {
                            ints[scopeNum].Add(match.Value);
                        }
                    }
                    else
                    {
                        list = new List<string>();
                        ints.Add(scopeNum, list);
                        ints[scopeNum].Add(match.Value);
                    }
                }
            }

            // doubles
            Console.Write("Doubles: ");
            foreach (var item in doubles)
            {
                foreach (var item2 in item.Value)
                {
                    resultList.Add(item2);
                }
            }
            resultList = resultList.Where(s => !string.IsNullOrWhiteSpace(s)).ToList();
            resultList.Sort();

            if (!resultList.Any())
            {
                Console.WriteLine("None");
            }
            else
            {
                string result = String.Join(", ", resultList);
                Console.WriteLine(result);
            }
            // Ints
            resultList = new List<string>();
            Console.Write("Ints: ");
            foreach (var item in ints)
            {
                foreach (var item2 in item.Value)
                {
                    resultList.Add(item2);
                }
            }
            resultList = resultList.Where(s => !string.IsNullOrWhiteSpace(s)).ToList();
            resultList.Sort();

            if (!resultList.Any())
            {
                Console.WriteLine("None");
            }
            else
            {
                string result = String.Join(", ", resultList);
                Console.WriteLine(result);
            }
        }