首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

月薪4000的笔试题目,该如何解决

2012-02-04 
月薪4000的笔试题目题目1:实现一个用户订阅邮件的场景描述:1)用户使用邮件来注册2)系统在5分钟内发送激活

月薪4000的笔试题目
题目1:实现一个用户订阅邮件的场景
描述:
1)用户使用邮件来注册
2)系统在5分钟内发送激活链接的邮件
3)用户点击邮件后,激活用户,结束
4)管理员可以查看已经激活和未激活的用户列表
5)无需实现用户登录

题目2:有一个表product( Description nvarchar (1000), Order int ) ,表中有5条记录,每条记录的Description字段都有内容,内容的字符数量有长有短。要求实现一个网页,以一个列表显示product的Description,要求按照Order来排序, 列表的宽度为200,高度为150,超长度的Description自动折行,5条记录如果总共的高度超过150,那么只显示到150高度范围的内容,其他内容忽略掉,并且最后一行加上…表示,

例如:

其中,1和2都是Order的值,后面就是Description的值。


题目3:有一个表 ordertable(price money,id int), 表中有50条记录,其中price中数据是不规则的,要求用一条查询语句取出price的和最大的连续5条记录
 例如:
110.00
25.00
36.00
48.00
51.00
620.00
760.00
84.00
93.00
102.00
1180.00
12120.00
131.00

和最大的连续5条记录就是
84.00
93.00
102.00
1180.00
12120.00

 
要求:1、使用asp.net 2.0
 2、使用C#语言
3、使用Sql Server 2000数据库
4、提交源代码和数据库脚本
请高手帮忙```急 在线等 明天早上8点要交呢 先谢谢各位大虾了


[解决办法]
题目1用数据库来保存激活码,并且加上是否激活标志符
题目2比较变态,Description nvarchar (1000),没这么定义字段的。先计算好高度150的表格能放多少个字,5条记录总文字数超出就用。。。表示
题目3 select top5 * from ordertable where id>(
select id from (select id, price+(select price+(select price+(select price+(select price+ from ordertable as o5 where o5.id=o4.id+1) from ordertable as o4 where o4.id=o3.id+1) from ordertable as o3 where o3.id=o2.id+1) from ordertable as o2 where o2.id=o1.id+1) as sumprice from ordertable as o1 order by sumprice desc))
[解决办法]
select top 5 * from ordertable where id >=( 
select id from 
(select top 1 id, price+(select price+(select price+(select price+(select price from ordertable o5 where o5.id=o4.id+1) from ordertable o4 where o4.id=o3.id+1) from ordertable o3 where o3.id=o2.id+1) from ordertable o2 where o2.id=o1.id+1) as sumprice from ordertable o1 order by sumprice desc 
) #
)
[解决办法]
1.zyowe应该可以吧,没试过
2.好像有个word-break,over-flow:hidden;
3.select *
from ordertable C
where abs(C.id-(
select top 1 id
from ordertable A
where id>=5
order by (select sum(price) from ordertable B
where abs(B.id-A.id)<=2) desc))<=2

[解决办法]
感觉第一二题应该是针对网站的,但第三题有点奇怪.很少出现的逻辑.



第一题没什么难度,
第二题:第二题用CSS很容易解决(这关系到目前流行的一些DIV+CSS的设计,大部分美工也没用上),也可以直接看看200x150能放多少个字节的内容,进行限制出来.

第三题:我还真做不出来
[解决办法]
第一个问题 答案 
发邮件时激活连接带上用户ID 和一个自动生成码 然后这个生成码保存在数据库中 如果需要安全 可以加密过 还有一个状态字段保持时候即或状态 注册的时候先置否 激活就根据GET传递过来的值对应用户ID和激活随机生成码 设置该用户ID的激活字段值为 是 登陆时检测 是否激活字段即可 
在激活时可以设置该ID状态为登陆状态(session) 既不需要重新登陆 
第二个问题 可以用CSS来解决,如果要用程序也可以, 计算字符个数 根据ASC 码 判断是否是全角或半角 如果一个全角就=2个半角 根据最后的半角个数 截断相应的文本字符 如果超过则再截去4个半角字符 然后用...代替 如果相等则不需要截断
第三个问题 
select top 5 * from ordertable where id<=(select top 1 id from ordertable order by price desc) order by id desc
[解决办法]
第二题的代码

 public string CutWords(string STR,int Size)
{
string a;
int bits = 0;
string restr="";
for (int i = 0; i < STR.Length; i++)
{
a = STR.Substring(i, 1);
bits+=System.Text.Encoding.Default.GetByteCount(a);
restr += a;
if (bits>Size-2)
break;


}
if (restr.Length > 3)
{
if (restr.Length < STR.Length)


{
int gad = 0;
string b="";
for (int h = 1; h <= 3; h++)
{
b=restr.Substring(restr.Length - h, 1);
gad += System.Text.Encoding.Default.GetByteCount(b);
if (gad >= 3)
{
restr = restr.Substring(0, restr.Length - h);
break;
}

}

restr += "...";
}
}
return restr;
}
[解决办法]
第三题 顺序调反了 现在更正顺序

select * from (select top 5 * from ordertable where id <=(select top 1 id from ordertable order by price desc) order by id desc) b order by id asc
[解决办法]
其他的没有什么好说的。讲讲第3题。
create table #t
(
id int,
price money
)
go
insert into #t select
1, 10.00 union all select
2, 5.00 union all select
3, 6.00 union all select
4, 8.00 union all select
5, 1.00 union all select
6, 20.00 union all select
7, 60.00 union all select
8, 4.00 union all select
9, 3.00 union all select
10, 2.00 union all select
11, 80.00 union all select
12, 120.00 union all select
13, 1.00

select top 5 * from #t
where id>=(
select top 1 id from (
select id,(select sum(price) from (
select top 5 price from #t m
where id>=o.id 
order by id 
)a
) price
from #t o
)r
order by price desc
)
order by id

drop table #t
/*

(13 row(s) affected)

id price
----------- --------------------- 
8 4.0000
9 3.0000
10 2.0000
11 80.0000
12 120.0000

(5 row(s) affected)
*/
[解决办法]
我感觉第3题目前为止,楼上的没有一个答出来的.
 例如: 
1 10.00 
2 5.00 
3 6.00 
4 8.00 
5 1.00 
6 20.00 
7 60.00 
8 4.00 
9 3.00 
10 2.00 
11 80.00 
12 120.00 
13 1.00 
请大家看清题目,price的和最大的连续5条记录
如果把第11和第13条记录互换一下位置.
很显然120+80是占了绝对的优势是连续5条和最大的.按大家以上的解答的话,是不会包括第13条(80.00)记录的.

另:我不是楼主的马甲,我只是也对此题目感兴趣而已.希望高手解答出来,让我们学习下.
[解决办法]
考虑到int不连续情况
1.插入临时连续ID
2.以1-5,2-6,3-7推进统计(MaxValue),推进到(N-4)--N(后面四条就省了)
3.取临时maxID 当 max(MaxValue)
4 取top 5 where 临时ID between maxID and maxID +5

不知有没有更好的思路....
[解决办法]
SELECT DISTINCT t1.id, t2.id, t3.id, t4.id, t5.id, t1.price+t2.price +t3.price+t4.price +t5.price
FROM [select t1.*,t2.*,t3.*,t4.*,t5.* from ordertable t1,ordertable t2,ordertable t3,ordertable t4 ,ordertable t5,ordertable t6
where t1.id<t2.id and t2.id<t3.id and t3.id<t4.id and t4.id<t5.id
and not exists (select id from ordertable a where (a.id>t1.id and a.id<t2.id ) or (a.id>t2.id and a.id<t3.id)
or(a.id>t3.id and a.id<t4.id) or(a.id>t4.id and a.id<t5.id)
)]. AS [p];

可以参考一下这个,我是我找朋友帮我写出来.嘿嘿.楼主,大家学习下.
[解决办法]
我试了一下第3题的解法:
建表table1 
id price
1 10.00 
2 5.00 
3 6.00 


4 8.00 
5 1.00 
6 20.00 
7 60.00 
8 4.00 
9 3.00 
10 2.00 
11 80.00 
12 120.00 
13 1.00 

======以下为SQL语句
declare @i int , @j int , @maxid int
declare @tmpsum int , @maxsum int , @maxidnum int

set @j=1
set @i= ( select count(*) as count1 from table1 )

set @j=@i-5+1 --得到表中连续5个记录的总个数

set @maxid=0
set @tmpsum=0
set @maxsum=0
set @maxidnum=0
while @j>0
begin

set @tmpsum=( select sum(price) as sumprice from table1 where id in (select top 5 id from table1 where id>=@maxid) ) --得到连续的5个记录的price总和

set @maxid=( select max(id) from table1 where id in (select top 2 id from table1 where id>=@maxid ) ) --得到下一个连续5个记录的开始id号
--select @maxid as maxid

if @tmpsum>@maxsum --找到比较大的和就保存起来(循环结束就得到最大的和了)
begin
set @maxsum=@tmpsum --较大的和
set @maxidnum=@maxid --较大的连续5个记录的开始id号
end 

set @j=@j-1
end

--打印结果
select @maxsum
select @maxidnum

本来想是挺简单的可我还是搞了2个小时才调试出来还没检查,而且还不是“一条”SQL语句,不知我去面试会不会直接被毙掉,呵呵

[解决办法]
不好意思有个小错误更正一下

=========以下为SQL语句
declare @i int , @j int , @maxid int
declare @tmpsum int , @maxsum int , @maxidnum int

set @j=1
set @i= ( select count(*) as count1 from table1 )

set @j=@i-5+1 --得到表中连续5个记录的总个数

set @maxid=0
set @tmpsum=0
set @maxsum=0
set @maxidnum=0
while @j>0
begin

set @tmpsum=( select sum(price) as sumprice from table1 where id in (select top 5 id from table1 where id>=@maxid) ) --得到连续的5个记录的price总和

set @maxid=( select max(id) from table1 where id in (select top 2 id from table1 where id>=@maxid ) ) --得到下一个连续5个记录的开始id号
--select @maxid as maxid

if @tmpsum>@maxsum --找到比较大的和就保存起来(循环结束就得到最大的和了)
begin
set @maxsum=@tmpsum --较大的和
set @maxidnum=(select top 1 id from table1 where id<@maxid order by id desc) --较大的连续5个记录的开始id号
end 

set @j=@j-1
end

--打印结果
select @maxsum
select @maxidnum

select top 5 * from table1 where id>=@maxidnum

[解决办法]
我那只是一种较通用思路,拿去面试只能被毙掉。

到现在好像只有onekey的解法是没问题的能得出总和和排列

select top 5 * from ordertable where id >=(
select id from
(select top 1 id, price+(select price+(select price+(select price+(select price from ordertable o5 where o5.id=o4.id+1) from [1] o4 where o4.id=o3.id+1) from ordertable o3 where o3.id=o2.id+1) from ordertable o2 where o2.id=o1.id+1) as sumprice from ordertable o1 order by sumprice desc
) #
) compute sum(price)


[解决办法]
关于第三题,还没结贴啊?
方法有几种:
1.就象上面我写的:
select * from
ordertable a,ordertable b,ordertable c,ordertable d,ordertable e 
where a.id+1=b.id and b.id+1=c.id and c.id+1=d.id and d.id+1=e.id 
and (a.price+b.price+c.price+d.price+e.price)=( 
select max(a.price+b.price+c.price+d.price+e.price) from ordertable a,ordertable b,ordertable c,ordertable d,ordertable e 
where a.id+1=b.id and b.id+1=c.id and c.id+1=d.id and d.id+1=e.id ) 


2.复杂一些的:
select id,id+1,id+2,id+3,id+4,sumprice from
(select a.id,(select sum(price) from ordertable b where a.id<=b.id and a.id+ 4>=b.id)as sumprice
from ordertable a )x 
where sumprice =
 (select max(sumprice) from 
(select a.id,(select sum(price) from ordertable b where a.id<=b.id and a.id+ 4>=b.id)as sumprice
from ordertable a )x)



[解决办法]
select top 5 * from #t 
where id >=(
select top 1 id from (
select id,(select sum(price) from ( 
select top 5 price from #t m 
where id >=o.id
order by id
)a 
) price 
from #t o 
)r 
order by price desc 

order by id 
不是一行就不是一条??

热点排行