//冒泡排序
    public class bubblesorter
    {
        public void sort(int[] list)
        {
            int i, j, temp;
            bool done = false;
            j = 1;
            while ((j < list.Length) && (!done))
            {
                done = true;
                for (i = 0; i < list.Length - j; i++)
                {
                    if (list[i] > list[i + 1])
                    {
                        done = false;
                        temp = list[i];
                        list[i] = list[i + 1];
                        list[i + 1] = temp;
                    }
                }
                    j++;
            }
        }
    }
    //选择排序
    public class selectionsorter
    {
        private int min;
        public void sort(int[] list)
        {
            for (int i = 0; i < list.Length - 1; i++)
            {
                min = i;
                for (int j = i + 1; j < list.Length; j++)
                {
                    if (list[j] < list[min])
                        min = j;
                }
                int t = list[min];
                list[min] = list[i];
                list[i] = t;
            }
        }
    }
    //插入排序
    public class insertionsorter
    {
        public void sort(int[] list)
        {
            for (int i = 1; i < list.Length; i++)
            {
                int t = list[i];
                int j = i;
                while ((j > 0) && (list[j - 1] > t))
                {
                    list[j] = list[j - 1];
                    --j;
                }
                list[j] = t;
            }
        }
    }

2.有一列数1,1,2,3,5,........求第30个数.

public class MainClass
{
    public static void Main()
    {
        Console.WriteLine(Foo(30));
    }
    public static int Foo(int i)
    {
        if (i <= 0)
            return 0;
        else if (i > 0 && i <= 2)
            return 1;
        else return Foo(i - 1) + Foo(i - 2);
    }
}

3. 程序设计: 猫大叫一声,所有的老鼠都开始逃跑,主人被惊醒。

    public delegate void SubEventHandler(); 
    public abstract class Subject 
    { 
        public event SubEventHandler SubEvent; 
        protected void FireAway() 
        { 
            if (this.SubEvent != null) 
                this.SubEvent(); 
        }   
    } 
    public class Cat : Subject 
    {  
        public void Cry() 
        { 
            Console.WriteLine(cat cryed.); 
            this.FireAway(); 
        } 
    } 
    public abstract class Observer 
    { 
        public Observer(Subject sub) 
        { 
            sub.SubEvent += new SubEventHandler(Response); 
        } 
        public abstract void Response();    
    } 
    public class Mouse : Observer 
    { 
        private string name; 
        public Mouse(string name, Subject sub) : base(sub) 
        {   
            this.name = name; 
        } 
        public override void Response() 
        { 
            Console.WriteLine(name +  attempt to escape!); 
        } 
    } 
    public class Master : Observer 
    { 
        public Master(Subject sub) : base(sub){} 
        public override void Response() 
        { 
            Console.WriteLine(host waken); 
        } 
    } 
    class Class1 
    { 
        static void Main(string[] args) 
        { 
            Cat cat = new Cat(); 
            Mouse mouse1 = new Mouse(mouse1, cat); 
            Mouse mouse2 = new Mouse(mouse2, cat); 
            Master master = new Master(cat); 
            cat.Cry(); 
        } 

    } 

4.有一个字符串 "I am a good man",设计一个函数,返回 "man good a am I"。

5.A、B、C、D、E五名学生有可能参加计算机竞赛,根据下列条件判断哪些
  人参加了竞赛:

(1)A参加时,B也参加;

(2)B和C只有一个人参加;

(3)C和D或者都参加,或者都不参加;

(4)D和E中至少有一个人参加;

(5)如果E参加,那么A和D也都参加。

        static void Main(string[] args)
        {

            char[] name={'A','B','C','D','E'};
            int[] value = new int[5];
            for (value[0]=0;value[0]<2;value [0]++)
                for (value[1]=0; value[1] < 2; value[1]++)
                    for (value[2]=0; value[2] < 2; value[2]++)
                        for (value[3]=0; value[3] < 2; value[3]++)
                            for (value[4]=0; value[4] < 2; value[4]++)
                            {
                                if ((value[1] >= value[0]) && (value[1] + value[2] == 1) && (value[2] == value[3]) && (value[3] + value[4]==1) && (value[4]==0 || value[4]==1 && value[0]==1 && value[3]==1))
                                {
                                    for (int i = 0; i < 5; i++)
                                    {
                                        if (value[i]==1)
                                        {
                                            Console.WriteLine("{0}参加", name[i]);
                                        }
                                        else
                                        {
                                            Console.WriteLine("{0}不参加", name[i]);
                                        }
                                    }
                                }
                            }
}

6.题目:
a user entered an integer value into a text box. Without using a buit-in library, convert the numeric string to its integer representation.

static int StringTolnt(string s)
        {
            int sum = 0;
            for (int i = 0; i < s.Length; i++)
                sum = sum * 10 + (s[i] - '0');
            return sum;
        }
恋花望月轻轻唱 听雨随风悄悄追

C#常见算法题目的更多相关文章

  1. C#常见算法题目(面试准备)

    1.写出冒泡,选择,插入排序算法.     //冒泡排序    public class bubblesorter    {        public void sort(int[] list)   ...

  2. JS常见算法题目

      最近收集了几个经典JS题目,比较有代表性,分享一下:   1.xiaoshuo-ss-sfff-fe  变为驼峰xiaoshuoSsSfffFe function getCamelCase(str ...

  3. iOS面试中常见的算法题目

    一.前言 这里是在iOS求职中自己遇到的算法题,希望对大家有所帮助.不定期更新.如果大家想在线运行代码调试,可以将代码拷贝到这里.然后进行调试.下面就是常见的算法题目. 二.正文 1.就n的阶乘.(这 ...

  4. acm常见算法及例题

    转自:http://blog.csdn.net/hengjie2009/article/details/7540135 acm常见算法及例题  初期:一.基本算法:     (1)枚举. (poj17 ...

  5. 字符串匹配常见算法(BF,RK,KMP,BM,Sunday)

    今日了解了一下字符串匹配的各种方法. 并对sundaysearch算法实现并且单元. 字符串匹配算法,是在实际工程中经常遇到的问题,也是各大公司笔试面试的常考题目.此算法通常输入为原字符串(strin ...

  6. BAT网络运维常见面试题目总结

    BAT常见面试题目总结 Author:Danbo 2015-7-11 TCP/IP详解鸟哥Linux的书网络安全ping的原理make的过程文件有哪些类型各种Linux发行版的区别.有关suid的作用 ...

  7. Top Coder算法题目浏览器

    作者:Lucida 微博:@peng_gong 豆瓣:@figure9 原文链接:http://zh.lucida.me/blog/top-code-offline-browser/ 关于 左耳朵耗子 ...

  8. Hadoop学习笔记—12.MapReduce中的常见算法

    一.MapReduce中有哪些常见算法 (1)经典之王:单词计数 这个是MapReduce的经典案例,经典的不能再经典了! (2)数据去重 "数据去重"主要是为了掌握和利用并行化思 ...

  9. 一道算法题目, 二行代码, Binary Tree

    June 8, 2015 我最喜欢的一道算法题目, 二行代码. 编程序需要很强的逻辑思维, 多问几个为什么, 可不可以简化.想一想, 二行代码, 五分钟就可以搞定; 2015年网上大家热议的 Home ...

随机推荐

  1. RSA私钥和公钥文件格式 (pkcs#1, pkcs#8, pkcs#12, pem)

    RSA私钥和公钥文件格式 (pkcs#1, pkcs#8, pkcs#12, pem) 2018年03月07日 11:57:22 阅读数:674 Format Name Description PKC ...

  2. Java经典设计模式之七大结构型模式

    转载: Java经典设计模式之七大结构型模式 博主在大三的时候有上过设计模式这一门课,但是当时很多都基本没有听懂,重点是也没有细听,因为觉得没什么卵用,硬是要搞那么复杂干嘛.因此设计模式建议工作半年以 ...

  3. UVA 1400."Ray, Pass me the dishes!" -分治+线段树区间合并(常规操作+维护端点)并输出最优的区间的左右端点-(洛谷 小白逛公园 升级版)

    "Ray, Pass me the dishes!" UVA - 1400 题意就是线段树区间子段最大和,线段树区间合并,但是这道题还要求输出最大和的子段的左右端点.要求字典序最小 ...

  4. Building Robust and Flexible Event System in Unity3D

    Building Robust and Flexible Event System in Unity3D 1. Prerequisites 1.1 Observer Pattern According ...

  5. NOIP2018游记(退役记。)

    Noip2018游记 这可能是写的最后一篇博客? \(Day0\) 早上六点从学校出发? 早上有雾,在车上扯淡,睡觉. 莫名其妙到了中午,想着午饭怎么解决,后来才知道早上发的四个面包竟然就包括我的午饭 ...

  6. xss可用事件

    onabort onafterprint onbeforeprint onbeforeunload onblur oncanplay oncanplaythrough onchange onclick ...

  7. java console 到文件

    System.setOut(new PrintStream(new FileOutputStream("c:\\temp\\test1.txt"))); System.out.pr ...

  8. spring-cloud学习BUG小结

    1.com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: c ...

  9. python语言特性总结

    一直想学习python,虽然编程写了不少,但有时仍不得要领.这篇blog主要是记录python的一些主要特性. 前言 python学习总结,包括python的一些基本语法,高级特性,函数式编程,面向对 ...

  10. BZOJ4599[JLoi2016&LNoi2016]成绩比较(dp+拉格朗日插值)

    这个题我们首先可以dp,f[i][j]表示前i个科目恰好碾压了j个人的方案数,然后进行转移.我们先不考虑每个人的分数,先只关心和B的相对大小关系.我们设R[i]为第i科比B分数少的人数,则有f[i][ ...