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] + "\n");
}
//九九乘法表
//int i, j;
//for (i = 1; i <= 9; i++)
//{
// for (j = 1; j <= i; j++)
// {
// Response.Write(j+"*"+i+"="+i*j+"\n");
// }
//}
/*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;
}
}
net字符串倒置和冒泡排序的更多相关文章
- 【算法和数据结构】_11_小算法_itoa、ftoa及字符串倒置
[1]main.c /**************************************************** * * 把整数按照进制数转换为相应进制的字符串 *(要考虑符号),比如 ...
- C#字符串倒置函数的代码
把内容过程比较常用的内容珍藏起来,下边内容内容是关于C#字符串倒置函数的内容. public static string Reverse(string ReverseString) { String ...
- C字符串倒置-中部对称
问题如图 Code #include<stdio.h> #include<string.h> #define MAX_LENGTH 10//最大字符串长度 void inver ...
- 笔试算法题(01):字符串倒置 & 八皇后问题
出题:将字符串“ABCD1234efgh”进行前后对调: 分析: 常见的考查指针使用的案例,知道字符串长度之后,依次交换位置i以及位置(length-1-i)上的内容,直到重叠: 注意不能直接修改指针 ...
- C016:字符串倒置
代码: #include "stdafx.h" #include <string.h> int _tmain(int argc, _TCHAR* argv[]) { c ...
- Leetcode 125 Valid Palindrome 字符串处理
题意:判断字符串是否是回文字符串 先将所有的字母和数字字符保留,并将大写字母转化成小写字母,然后将字符串倒置,比较前后两个字符串是否相同. 该题最好的解法可以模仿 Leetcode 345 Rever ...
- java 字符串笔记
java字符串当中有三个关于字符串对象的类. String 首先谈论下他们各自的含义: 1.String含义为引用数据类型,是字符串常量.是不可变的对象,(显然线程安全)在每次对string类型进行改 ...
- 51nod 1092(lcs)回文字符串
题目:给你一个字符串,问添加最少的字符数目,使之成为回文串 解题思路:将字符串倒置,求出字符串和倒置串的最长公共子序列,字符串的长度减去lcs的长度就是了.. 代码:#include<iostr ...
- 【Python初级】由判定回文数想到的,关于深浅复制,以及字符串反转的问题
尝试用Python实现可以说是一个很经典的问题,判断回文数. 让我们再来看看回文数是怎么定义的: 回数是指从左向右读和从右向左读都是一样的数,例如1,121,909,666等 解决这个问题的思路,可以 ...
随机推荐
- 整理我的Git常见问题和命令
整理我的Git常见问题和命令 目录 整理我的Git常见问题和命令 提交注释规范 合并分支 clone & 切换分支 支持中文路径显示 账户及密码 基于远程分支创建本地分支 提交注释规范 举例: ...
- shell脚本的使用该熟练起来了,你说呢?(篇三)
继续前一篇的文章: shell脚本的使用该熟练起来了,你说呢?(篇一) shell脚本的使用该熟练起来了,你说呢?(篇二) 文章里面测试的命令脚本文件,大家关注我公众号后,可以私信我领取文件. 作者: ...
- UVA-12304 2D Geometry 110 in 1! (有关圆的基本操作)
UVA-12304 2D Geometry 110 in 1! 该问题包含以下几个子问题 CircumscribedCircle x1 y1 x2 y2 x3 y3 : 三角形外接圆 Inscribe ...
- c语言实现--顺序表操作
经过三天的时间终于把顺序表的操作实现搞定了.(主要是在测试部分停留了太长时间) 1;线性表顺序存储的概念:指的是在内存中用一段地址连续的存储单元依次存储线性表中的元素. 2;采用的实现方式:一段地址连 ...
- 【noi 2.6_6252】带通配符的字符串匹配(DP)
题意:给出一个带有通配符("?"可以代替一个字符,"*"可以代替零个或多个字符)的a字符串和一个不带通配符的b字符串,判断他们是否能够匹配. 解法:f[i][j ...
- 整体算力提升40% 芯片级安全防护 | 阿里云发布第七代ECS云服务器
2 月 8 日,阿里云宣布推出第七代 ECS 云服务器产品家族,基于最新的神龙架构,相较于上一代整体算力提升 40%,容器部署密度最大可提升 6 倍,是最佳的云原生载体,此外全量搭载安全芯片,实现&q ...
- Atlas 分表功能
目录 分表原因 分表方式 Atlas 分表 分表思路 配置 Atlas 创建原表 创建分表 数据测试 分表原因 1.数据过多,访问缓慢 2.创建索引时重新排序,创建缓慢,并且占用大量的磁盘空间 分表方 ...
- 忘记Mysql的root用户密码处理方法(以mysql 5.5.33为例)
1.修改mysql服务器的脚本 ~]#vi /etc/rc.d/init.d/mysqld #找到$bindir/mysqld_safe --datadir="$datadir" ...
- 排序算法 以及HKU的一些数据结构 相关题目 以及 K叉树,二叉树 排列
冒泡排序.选择排序.快速排序.插入排序.希尔排序.归并排序.基数排序以及堆排序,桶排序 https://www.cnblogs.com/Glory-D/p/7884525.html https://b ...
- 关于ucore实验一的资料查找
任务:阅读实验一makefile 搞清楚ucore.img是如何构建的 $@ $< $^ 这三个变量分别是什么意思 https://blog.csdn.net/YEYUANGEN/arti ...