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;
   }
}

原文地址:https://www.cnblogs.com/panjuan/p/3830967.html