zoukankan      html  css  js  c++  java
  • net字符串倒置和冒泡排序

    using System;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Text;
    using System.Collections.Generic;
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SortArr();
            }

        }
        #region
        //取反
        private string Revese(string str)
        {
            StringBuilder SB = new StringBuilder();
            for (int i = str.Length - 1; i >= 0; i--)
            {
                SB.Append(str[i]);

            }
            return SB.ToString();
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string num = Revese(this.TextBox1.Text.ToString());
            this.TextBox2.Text = num;
        }
        #endregion
        #region
        //1。1。2。3。5。8。13。21。34。55 用递归的方法算出第30数是多少?
        //public int function(int n)
        //{
        //    if (n == 1)
        //    {
        //        return 1;
        //    }
        //    else if (n == 2)
        //    {
        //        return 1;
        //    }
        //    else
        //    {
        //        return function(n - 2) + function(n - 1);
        //    }
        //}
        /*1*2*3*4...*/
        public int function(int n)
        {
            if (n == 1)
            {
                return 1;
            }
            else
            {
                return n * function(n - 1);
            }
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            int num = function(int.Parse(this.TextBox3.Text));
            this.TextBox4.Text = num.ToString();
        }
        #endregion
        #region
        //冒泡排序
        public void SortArr()
        {
            int i;
            int j;
            int[] arr = { 79, 56, 90, 4, 32, 27, 16, 88, 35 };
            //外层循环控制轮数
            for (i = 0; i < arr.Length - 1; i++)
            {
                //内层循环控制每轮比较的次数
                for (j = 0; j < arr.Length - 1 - i; j++)
                {
                    //条件判断
                    if (arr[j] > arr[j + 1])
                    {
                        int temp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = temp;
                    }

                }
            }
            for (i = 0; i < 9; i++)
            {
                Response.Write(arr[i] + " ");
            }

            //九九乘法表
            //int i, j;
            //for (i = 1; i <= 9; i++)
            //{
            //    for (j = 1; j <= i; j++)
            //    {
            //        Response.Write(j+"*"+i+"="+i*j+" ");
            //    }
            //}
            /*1-2+3-4...+m*/
            //string strsql = "";
            //for (int i = 1; i <= 100000; i++)
            //{
            //    if (i == 1)
            //    {
            //        strsql += i;
            //    }
            //    else
            //    {
            //        if (i % 2 == 0)
            //        {
            //            strsql += "-" + i;
            //        }
            //        else
            //        {
            //            strsql += "+" + i;
            //        }
            //    }
            //}
            //Response.Write(strsql);
            /*1+3+5+7*/
            //string strsql = "";
            //for (int i = 0; i < 100; i++)
            //{
            //    if (i == 1)
            //    {
            //        strsql += i;
            //    }
            //    else
            //    {
            //        if (i % 2 != 0)
            //        {
            //            strsql += "+" + i;
            //        }
            //    }
            //}
            //Response.Write(strsql);

        }
        #endregion
        /*算字母总和*/
        protected void Button3_Click(object sender, EventArgs e)
        {
          Response.Write(Show(this.TextBox5.Text));
        }
      public static int Show(string strInput)
       {
            //strInput = strInput.ToUpper();
            ////A=1,B=2,z=26,那么what=52
            //string[] strWords = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
            //int s = 0;
            //for (int i = 0; i < strInput.Length; i++)
            //{
            //    string str = strInput.Substring(i, 1);
            //    for (int j = 0; j < strWords.Length; j++)
            //    {
            //        if (str == strWords[j])
            //        {
            //            s += j + 1;
            //            break;
            //        }
            //    }
            //}
            //return s;
           strInput = strInput.ToUpper();
           string[] strWords = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
           int s = 0;
           for (int i = 0; i < strInput.Length; i++)
           {
               string str = strInput.Substring(i,1);
               for (int j = 0; j < strWords.Length; j++)
               {
                   if (str == strWords[j])
                   {
                       s += j + 1;
                       break;
                   }
               }
           }
           return s;
       }
    }

  • 相关阅读:
    (4.25)Sqlserver中 登录用户只能看到自己拥有权限的库
    【查阅】mysql配置文件/参数文件重要参数笔录(my.cnf)
    【监控笔记】【2.5】DML(CDC)、DDL(DDL触发器)跟踪数据更改,数据库审计
    SQL Server 2008中的CDC(Change Data Capture)功能使用及释疑
    【监控笔记】【2.4】SQL Server中的 Ring Buffer 诊断各种系统资源压力情况
    【监控笔记】【2.3】扩展事件——慢查询SQL(执行超过3S的SQL)
    【监控笔记】【2.2】扩展事件——死锁监控
    最小配置启动SQL SERVER,更改SQL Server最大内存大小导致不能启动的解决方法
    【监控笔记】【2.1】扩展事件
    【扩展事件】跟踪超过3秒的SQL
  • 原文地址:https://www.cnblogs.com/panjuan/p/3830967.html
Copyright © 2011-2022 走看看