1)有表 Table_1,结构如下:
Id,StudentName,Course,Score
表中有所有学生的各个科目的成绩,找出各科前3名的学生。
相关创建表代码
CREATE TABLE [dbo].[Table_1](
[id] [int] NULL,
[studentName] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[courseName] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[score] [int] NULL
) ON [PRIMARY]
insert into table_1 values(1,'Michael','Math',100)
insert into table_1 values(2,'Michael','English',90)
insert into table_1 values(3,'Simon','Math',65)
insert into table_1 values(3,'Simon','English',99)
insert into table_1 values(4,'Leo','Math',60)
insert into table_1 values(5,'Leo','English',30)
insert into table_1 values(6,'Bendy','Math',87)
insert into table_1 values(7,'Bendy','English',85)
insert into table_1 values(8,'Leo','Chinese',40)
insert into table_1 values(9,'Bendy','Chinese',80)
insert into table_1 values(10,'Michael','Chinese',50)
insert into table_1 values(11,'Simon','Chinese',78)
insert into table_1 values(12,'K','Math',50)
insert into table_1 values(13,'K','English',70)
insert into table_1 values(14,'k','Chinese',55)
回家后用了1个小时(惭愧,放下Sql时间太久啦),终于做好了答案:
select a.* from Table_1 a
where score
in (select top 3 score from Table_1 b
where a.courseName=b.courseName
order by score desc) order by courseName,score desc
2)给出一个长度为65000int数组。里面是无序,可重复的数值,范围是0-65535之间。找出不在这个数组里面,但是在0-65535之间的整数。
答案如下,不知道有没有更好的办法
- using System;
- namespace ConsoleApplication2
- {
- class Program
- {
- static void Main(string[] args)
- {
- var input = new int[3];
- var ra = new Random(3);
- for(int i=0;i<input.Length;i++)
- {
- input[i]= ra.Next(0, 65535);
- }
- bool[] setter = new bool[65535];
- for(int i=0;i<input.Length;i++)
- {
- setter[input[i]] = true;
- }
- int number = 0;
- for(int i=0;i<setter.Length;i++)
- {
- if (!setter[i])
- {
- number++;
- }
- }
- Console.WriteLine(number);
- Console.Read();
- }
- }
- }
- using System;
- namespace ConsoleApplication2
- {
- class Class1
- {
- static void Main(string[] args)
- {
- char[] a=new char[] {'a', 'b', 'c'};
- Output(a, 0);
- Console.Read();
- }
- public static void Output(char[] a, int position)
- {
- if (position == a.Length)
- Console.WriteLine(a);
- for(int i=position;i<a.Length;i++)
- {
- char temp = a[i];
- a[i] = a[position];
- a[position] = temp;
- Output(a, position + 1);
- }
- }
- }
- }