数据结构 c# 字符串的处理
来源:互联网 发布:网吧服务器攻击软件 编辑:程序博客网 时间:2024/04/29 19:55
1. 字符串的逆转
using System;
class Output
{
public static void Main(string[] args)
{
//*********************String reverse******************
Console.WriteLine("Please input a sentence:");
string str = Console.ReadLine();
char[] arrychar = str.ToCharArray();
for (int i = 0; i < arrychar.Length/2; i++)
{
char tem;
tem = arrychar[i];
arrychar[i] = arrychar[arrychar.Length - i - 1];
arrychar[arrychar.Length - i - 1] = tem;
}
string arry = new string(arrychar);
Console.Write(arry);
Console.ReadKey();
}
}
2. 输入一字符串要求输出后只有数字和字母,其它的空格特殊字符都不要
using System;
class Output
{
public static void Main(string[] args)
{
//*********************Get Number and Char******************
Console.WriteLine("Please input a sentence:");
string str = Console.ReadLine();
char[] arrychar = str.ToCharArray();
char[] temp = new char[arrychar.Length];
int j = 0;
foreach (char ch in arrychar)
{
if (char.IsLetterOrDigit(ch))
{
temp[j] = ch;
j++;
}
}
string arry = new string(temp);
Console.Write(arry);
Console.ReadKey();
}
}
3. 二分查找算法实现
using System;
namespace Search
{
public class BinarySearch
{
public static void Main(string[] args)
{
//是输入一串数组
Console.WriteLine("请出入一串整数:");
string num = Console.ReadLine();
string[] arryNum;
arryNum = num.Split(new char[] { ' ' });
int[] intNum = new int[arryNum.Length];
int i = 0;
foreach (string s in arryNum)
{
intNum[i++] = Convert.ToInt32(s);
}
Array.Sort(intNum);
Console.WriteLine("请输入要查找的数:");
int findnum = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("数{0}的位置是:{1}", findnum, Search(intNum, findnum));
Console.ReadKey();
//确定的一串数组;
//int[] arryint = new int[] { 1, 3, 5, 7, 9, 10, 14, 18 };
//int j = Search(arryint, 9);
//Console.WriteLine("所查找的数的位置为:{0}", j);
//Console.ReadKey();
}
static int Search(int[] data, int key)
{
int low = 0;
int high = data.Length - 1;
while (low <= high)
{
int middle = (low + high) / 2;
if (data[middle] == key)
{
return middle + 1;
}
else if (data[middle] < key)
{
low = middle + 1;
}
else
{
high = middle - 1;
}
}
return -1;
}
#region nomalSearch
static int nomalSearch(int[] data, int key)
{
int i ;
for (i=0; i < data.Length; i++)
{
if (data[i] == key)
{
return i+1;
}
}
return -1;
}
#endregion
}
}
- 数据结构 c# 字符串的处理
- C#字符串的处理
- C# 关于字符串的处理
- C#中字符串的处理
- C#中字符串的处理
- C#简单的字符串处理
- C#中字符串的处理
- C#总结---字符串的处理
- C#中字符串的处理
- C#中常用处理字符串的方法
- c# 字符串常用的处理方法
- C#中常用的字符串处理函数
- C#中常用的字符串处理方法
- C#中常用处理字符串的方法
- C#中对字符串的处理
- C#中字符串的处理方法
- C#中JSON字符串的处理
- C# DateTime时间和字符串的处理
- 忆龙2009:Brew FAQ-常见问答(4)
- Delphi控制摄像头
- 忆龙2009:Brew FAQ-常见问答(3)
- MINIX源码
- MTK:IDLE输入超长号码显示变化 转)
- 数据结构 c# 字符串的处理
- 文本区域 换符号
- linux下内存管理简介
- 大数据量的处理
- 忆龙2009:Brew FAQ-常见问答(2)
- 谈话节目点播
- office 2010 安装,提示无法打开注册表项 error 1402
- 忆龙2009:Brew FAQ-常见问答(1)
- CUDA起点