博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
面试小题
阅读量:4338 次
发布时间:2019-06-07

本文共 3862 字,大约阅读时间需要 12 分钟。

题目不难,总结如下:

1.冒泡排序:

冒泡排序
1    class Program 2     { 3         static void Main(string[] args) 4         { 5             string temp=Console.ReadLine(); 6             string[] tempArray=temp.Split(' '); 7             int[] arry = new int[tempArray.Length]; 8  9             for (int i = 0; i < tempArray.Length; i++)10             {11                 arry[i] = Convert.ToInt32(tempArray[i]);12                    13             }14 15             PopSort(arry, true);16             PrintArray(arry);17             PopSort(arry,false);18             PrintArray(arry);19         }20 21         static void PrintArray(int[] arry)22         {23             for (int i = 0; i < arry.Length ; i++)24             {25                 Console.Write("{0} ",arry[i]);26             }27             Console.WriteLine();28         }29 30         static void PopSort(int[] arry,bool Increase)31         {32             for(int i=0;i
arry[j + 1])39 {40 int temp = arry[j];41 arry[j] = arry[j + 1];42 arry[j + 1] = temp;43 }44 }45 else46 {47 if (arry[j] < arry[j + 1])48 {49 int temp = arry[j];50 arry[j] = arry[j + 1];51 arry[j + 1] = temp;52 }53 }54 }55 }56 }57 }

2.字符串倒置

反序输出字符串
1  class Program 2     { 3         static void Main(string[] args) 4         { 5             string temp = Console.ReadLine(); 6             Console.WriteLine("before convert:{0}", temp); 7             StringBuilder sb = new StringBuilder(temp);           8             for (int i = 0; i < sb.Length / 2; i++) 9             {10                 char c = sb[i];11                 sb[i] = sb[sb.Length - i - 1];12                 sb[sb.Length - i - 1] = c;13                 14             }15 16             temp = sb.ToString();17             Console.WriteLine("after convert:{0}",temp);18 19 20         }21     }

3.二分法查找数组中的某个值

二分查找
1  class Program 2     { 3         static void Main(string[] args) 4         { 5             int[] arry = new int[] { 23,45,67,78,100}; 6             int a=100; 7             int b = 23; 8             int c = 67; 9             int d = 40;10             Console.WriteLine("index of {0} is {1}",a, Find(arry, a));11             Console.WriteLine("index of {0} is {1}",b, Find(arry, b));12             Console.WriteLine("index of {0} is {1}",c, Find(arry, c));13             Console.WriteLine("index of {0} is {1}",d, Find(arry, d));14         }15 16         static int Find(int[] arry, int value)17         {18             int low = 0;19             int high = arry.Length;20            21 22             while (low <= high)23             {24                 int mid = (low + high) / 2;25                 if (arry[mid] == value)26                 {27                     return mid;28                 }29                 else if (arry[mid] < value)30                 {31                     low = mid + 1;32                 }33                 else34                 {35                     high = mid - 1;36                 }37 38             }39          40                 return -1;41         }42     }

4.输入数字m,n,从1,2,3...n数列中取几个数,使其和等于m,输出所有可能的组合。

View Code
1 class Program 2     { 3         static void Main(string[] args) 4         { 5             int m = 15; 6             int n = 9; 7             int[] arry = new int[n]; 8             BagProblem(m, n, arry); 9         }10 11 12         static void printArray(int[] arry)13         {14             for(int i=0;i

 

 

 

转载于:https://www.cnblogs.com/marksun/archive/2013/04/22/3036697.html

你可能感兴趣的文章
图论知识,博客
查看>>
[原创]一篇无关技术的小日记(仅作暂存)
查看>>
20145303刘俊谦 Exp7 网络欺诈技术防范
查看>>
原生和jQuery的ajax用法
查看>>
iOS开发播放文本
查看>>
20145202马超《java》实验5
查看>>
JQuery 事件
查看>>
main(argc,argv[])
查看>>
第四阶段 15_Linux tomcat安装与配置
查看>>
NAS 创建大文件
查看>>
学习笔记-模块之xml文件处理
查看>>
接口测试用例
查看>>
Sybase IQ导出文件的几种方式
查看>>
案例:手动输入一个字符串,打散放进一个列表,小写字母反序 大写字母保持不变...
查看>>
linux 系统下 tar 的压缩与解压缩命令
查看>>
阿里负载均衡,配置中间证书问题(在starcom申请免费DV ssl)
查看>>
转:How to force a wordbreaker to be used in Sharepoint Search
查看>>
MySQL存储过程定时任务
查看>>
Python中and(逻辑与)计算法则
查看>>
POJ 3267 The Cow Lexicon(动态规划)
查看>>