一:题目大意
54张牌 要求随机 顺序会发生改变 今天面试的时候没搞出来 晕 脑子一片空白 现在为了安慰自己 回家写了一个 大家参考一下 
看看大家有没有什么简便的写法private string CreateRandomCode(int codeCount)
{
string allChar = "";
string randomCode = "";
int temp = -1; for(int i=1;i<55;i++)
{
allchar+=i.ToString()+","
} string[] allCharArray = allChar.Split(','); Random rand = new Random();
for(int i = 0; i < codeCount; i++)
{
if(temp != -1)
{
rand = new Random(i*temp*((int)DateTime.Now.Ticks));
}
int t = rand.Next(54);
if(temp == t)
{
return CreateRandomCode(codeCount);
}
temp = t;
randomCode += allCharArray[t];
}
return randomCode;
}调用CreateRandomCode(54)顺便回顾一下随机数的生成 面试的时候 忘了Random这个函数 晕倒 不知道该咋写了 顺便求一个另外简便的写法第二题题目大概 一个表 id,title,content,date1  写出插入,更新,删除的三个存储过程  这个题略过不讨论 一般人都知道

解决方案 »

  1.   

    晕啊,这么简单的问题还用递归?
    你不妨模仿一下洗牌的过程,不就几张牌翻来倒去吗?先假定54张牌是按序排放的, 然后随机产生两张牌的位置,并交换之. 循环N次.想洗乱一些N就大些.算法复杂度是O(N)级的,而你的是N平方级的
      

  2.   

    刚才又细看了一下,越发觉得你的算法臭,N平方级都算不上, 应该是N的阶乘的复杂度
    for(int i=1;i<55;i++)
    {
    allchar+=i.ToString()+","
    } string[] allCharArray = allChar.Split(',');
    这段Code用句不好听的话形容:脱了裤子打屁
      

  3.   

    很久没写console程序我也写个练下using System;
    using System.Collections;namespace RandomCode
    {
    /// <summary>
    /// 随机发54张牌
    /// </summary>
    class MySolution
    {
    class AppSolution
    {
    const int MAX = 54;
    ArrayList arrResoult;
    ArrayList arrResoultNum; public AppSolution()
    {
    arrResoult =  new ArrayList(MAX);
    arrResoultNum = new ArrayList(MAX); for(int i = 0;i < MAX;i++)
    {
    arrResoult.Add((int)0);
    arrResoultNum.Add((int)0);
    }
    } public void Run()
    {
    int Count = 0;
    int arrNum = 0;
    Random seed =  new Random(DateTime.Now.Millisecond);
    do 
    {
    arrNum = seed.Next(MAX);
    if((int)arrResoult[arrNum] < 1)
    {
    arrResoult[arrNum] = 1;
    arrResoultNum[Count] = arrNum;
    Count++;
    }
    }while(Count != MAX);
    } public void Display()
    {
    foreach(int arrNum in arrResoultNum)
    {
    Console.Write("{0}\t",arrNum);
    }
    Console.WriteLine();
    } public void Sort()
    {
    arrResoultNum.Sort();
    }
    } [STAThread]
    static void Main(string[] args)
    {
    AppSolution app = new AppSolution();
    app.Display();
    app.Run();
    app.Display();
    app.Sort();
    app.Display();
    string cmdInput = Console.ReadLine();
    }
    }
    }
      

  4.   

    原来seed.Next(MAX)就自动生成了与原先都不一样的随机数, 这大大降低了问题的复杂性.我原先还以为有可能产生相同的数.
      

  5.   

    今天去了和楼主一样的公司面试,当然题目也就一样结果连第2题都写错了存储过程里居然写了个string类型。。
      

  6.   

    快来架站,完全免费,不用装任何软件.魔术般的拥有你自己的宝盒.请来www.irbox.cn 注册会员,就可以拥有完全属于你自己的强劲站点.不用再给别人写博客,肥了他人的腰包,不用再寄人篱下,受人白眼,自己创建自己的个性站点.写自己的事情.
    另外 .cn 1元注册还剩最后一天,大家赶快去注册啊.配合我们免费服务.您立即就拥有自己的站点.注册域名请进 http://beijingidc.com/  (我也在这里注册的不错的)....  宝盒功能示例站点:www.codeman.cn  
    草根到底,人人建站
      

  7.   

    鍒氱湅浜嗕竴涓?c#鍏ラ棬缁忓吀閲岀殑鏂规硶鏂逛究澶у瀛︿範 甯栧嚭鏉?
    http://www.ibook8.com/Software/Catalog14/650.html涓嬭浇璇ュ浘涔?
    椤电爜 206椤
      

  8.   

    涓や釜for寰幆灏卞仛鍑烘潵浜?..涔﹀啓瑙勮寖绠椾笂鎷姬鍔犱笂娉ㄩ噴涔熶笉浼氳秴杩?0琛?..浣嗚繖涓嶆槸閲嶇偣...鍋囧鎴戞槸鑰冨畼...涓嶇敤闆嗗悎绫荤殑...鍜斿殦...
    涓嶇敤缁撴瀯鐨?..鍜斿殦...
    涓嶇敤鏋氫妇鐨?..鍜斿殦...濡傛灉瑕佹眰鍐嶄弗鏍肩偣...鐢ㄩ殢鏈烘暟鐨?..鍜斿殦...涓轰粈涔堬紵鍥犱负杩欐槸 C# 涓嶆槸 C...