一:题目大意
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 写出插入,更新,删除的三个存储过程 这个题略过不讨论 一般人都知道
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 写出插入,更新,删除的三个存储过程 这个题略过不讨论 一般人都知道
解决方案 »
- 一个关于gridview控件绑定的问题。急
- 问一下你几个关于Nhibernate和Spring.net的问题,请大家尽量帮我解答
- WEB读取WORD
- 发现asp.net区没什么好帖子可以讨论啦
- 在asp.net中输出VML矢量图的问题(在线等)
- datagrid選中行呈現行背景色為紅色 送分問題
- 一如何用javascript获得CheckBox被选中时,本行的值;二如何不用Javascript而在.aspx.cs中获得CheckBox被单击时事件
- CCS论坛会员共享谁做过?
- 我的JS+XMLHTTP的无刷新级联下拉框,怎么客户端接收不到数据
- 点击页面空白处应该是什么事件呢?
- 请看看这个left函数哪里有错
- 为什么我的Maxthon游览器总是要调一下"查看"-"编码"-"简体中文"才出现网页内容啊
你不妨模仿一下洗牌的过程,不就几张牌翻来倒去吗?先假定54张牌是按序排放的, 然后随机产生两张牌的位置,并交换之. 循环N次.想洗乱一些N就大些.算法复杂度是O(N)级的,而你的是N平方级的
for(int i=1;i<55;i++)
{
allchar+=i.ToString()+","
} string[] allCharArray = allChar.Split(',');
这段Code用句不好听的话形容:脱了裤子打屁
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();
}
}
}
另外 .cn 1元注册还剩最后一天,大家赶快去注册啊.配合我们免费服务.您立即就拥有自己的站点.注册域名请进 http://beijingidc.com/ (我也在这里注册的不错的).... 宝盒功能示例站点:www.codeman.cn
草根到底,人人建站
http://www.ibook8.com/Software/Catalog14/650.html涓嬭浇璇ュ浘涔?
椤电爜 206椤
涓嶇敤缁撴瀯鐨?..鍜斿殦...
涓嶇敤鏋氫妇鐨?..鍜斿殦...濡傛灉瑕佹眰鍐嶄弗鏍肩偣...鐢ㄩ殢鏈烘暟鐨?..鍜斿殦...涓轰粈涔堬紵鍥犱负杩欐槸 C# 涓嶆槸 C...