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等 解决这个问题的思路,可以 ...
随机推荐
- 一篇文章搞定Java注解^_^
0.序言 自己写这些文章本来想着自己系统的整理下知识,将知识串起来,后面复习用,或者以后年龄大了,去教育机构呀,拿出自己整理的笔记,你看这人爱总结爱分享,文笔也还能看,方便找工作不是. 很开心的是,有 ...
- Java 容器系列总结
为什么要使用集合 当我们需要保存一组类型相同的数据的时候,我们应该是用一个容器来保存,这个容器就是数组,但是,使用数组存储对象具有一定的弊端, 因为我们在实际开发中,存储的数据的类型是多种多样的,于是 ...
- G - 棋盘游戏
小希和Gardon在玩一个游戏:对一个N*M的棋盘,在格子里放尽量多的一些国际象棋里面的"车",并且使得他们不能互相攻击,这当然很简单,但是Gardon限制了只有某些格子才可以放, ...
- Educational Codeforces Round 97 (Rated for Div. 2) E. Make It Increasing(最长非下降子序列)
题目链接:https://codeforces.com/contest/1437/problem/E 题意 给出一个大小为 \(n\) 的数组 \(a\) 和一个下标数组 \(b\),每次操作可以选择 ...
- Testing Beta Round (Unrated)
比赛链接:https://codeforces.com/contest/1390 A. 123-sequence 题意 给出一个只含有 $1,2,3$ 的数组,问使所有元素相同至少要替换多少元素. 题 ...
- Codeforces Round #651 (Div. 2) E. Binary Subsequence Rotation(dp)
题目链接:https://codeforces.com/contest/1370/problem/E 题意 给出两个长为 $n$ 的 $01$ 串 $s$ 和 $t$,每次可以选择 $s$ 的一些下标 ...
- 【noi 2.6_6252】带通配符的字符串匹配(DP)
题意:给出一个带有通配符("?"可以代替一个字符,"*"可以代替零个或多个字符)的a字符串和一个不带通配符的b字符串,判断他们是否能够匹配. 解法:f[i][j ...
- Codeforces Round #575 (Div. 3) E. Connected Component on a Chessboard
传送门 题意: 给你一个黑白相间的1e9*1e9的棋盘,你需要从里面找出来由b个黑色的格子和w个白色的格子组成的连通器(就是你找出来的b+w个格子要连接在一起,不需要成环).问你可不可以找出来,如果可 ...
- Codeforces Round #670 (Div. 2) C. Link Cut Centroids (dfs,树)
C. Link Cut Centroids Fishing Prince loves trees, and he especially loves trees with only one centro ...
- Codeforces #640 div4 F~G (构造二连弹)
题意:求一个只由\(01\)组成的字符串,使得它所有长度为\(2\)的子串满足:每对子串的数字和为\(0,1,2\)的个数为\(a,b,c\). 题解:我们先考虑子串数字和为\(1\)的情况,构造出一 ...