Exemple #1
0
        public IActionResult Sumlists(int a, int b)
        {
            string astr  = a.ToString();
            var    alist = new LinkedList <int>();

            foreach (char c in astr)
            {
                alist.AddFirst(int.Parse(c.ToString()));
            }

            string bstr  = b.ToString();
            var    blist = new LinkedList <int>();

            foreach (char c in bstr)
            {
                blist.AddFirst(int.Parse(c.ToString()));
            }

            var res = Sum2lists(alist, blist);

            return(AjaxResponse.Create(
                       new AjaxResult()
            {
                Code = (int)AjaxResultCode.Ok,
                Result = res,
            }
                       ).ToJson());
        }
Exemple #2
0
        public IActionResult Sumarray(int[] arr)
        {
            if (arr == null || arr.Length == 0)
            {
                return(AjaxResponse.Create(
                           new AjaxResult()
                {
                    Code = (int)AjaxResultCode.Error,
                    ErrorMessage = "Введите массив",
                }
                           ).ToJson());
            }

            int[] narr = arr.Where(x => x % 2 != 0).ToArray();

            if (narr.Length < 2)
            {
                return(AjaxResponse.Create(
                           new AjaxResult()
                {
                    Code = (int)AjaxResultCode.Error,
                    ErrorMessage = "Недостаточно нечетных чисел",
                }
                           ).ToJson());
            }

            int sum = 0;

            for (int i = 0; i < narr.Length; i++)
            {
                if (i % 2 != 0)
                {
                    sum += Math.Abs(narr[i]);
                }
            }

            return(AjaxResponse.Create(
                       new AjaxResult()
            {
                Code = (int)AjaxResultCode.Ok,
                Result = sum,
            }
                       ).ToJson());
        }
Exemple #3
0
        public IActionResult Pal(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(AjaxResponse.Create(
                           new AjaxResult()
                {
                    Code = (int)AjaxResultCode.Error,
                    ErrorMessage = "Введите строку для проверки",
                }
                           ).ToJson());
            }

            string rtext = text.Reverse();

            if (rtext.Equals(text, StringComparison.OrdinalIgnoreCase))
            {
                return(AjaxResponse.Create(
                           new AjaxResult()
                {
                    Code = (int)AjaxResultCode.Ok,
                    Result = "Строка является палиндромом",
                }
                           ).ToJson());
            }
            else
            {
                return(AjaxResponse.Create(
                           new AjaxResult()
                {
                    Code = (int)AjaxResultCode.Ok,
                    Result = "Строка не является палиндромом",
                }
                           ).ToJson());
            }
        }