2020校招4399游戏开发岗笔试编程题(C#)
2020校招4399游戏开发岗笔试编程题(C#)
一、 小球自由落体,一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第n次落地时,共经过多少米?第n次反弹多高?
using System;
struct Value
{
public double sum;
public double hight;
}
class Program
{
public static void Main(string[] str)
{
int key = int.Parse(Console.ReadLine());
Value value = new Value();
value = Program.Ra(key);
Console.WriteLine($"{value.sum} {value.hight}");
}
public static Value Ra(int key)
{
double tempN = 100;
Value value = new Value();
for (int i = 0; i < key; i++)
{
value.sum += tempN * 2;
tempN *= 0.5f;
}
value.sum -= 100;
value.hight = tempN;
return value;
}
}
二、有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。
using System;
using System.Collections.Generic;
using System.Linq;
struct Person
{
public int number;
public int sort;
}
class Program
{
public static void Main(string[] str)
{
int key = int.Parse(Console.ReadLine());
Person person = new Person();
person = Program.Ra(key);
Console.WriteLine($"{person.number}");
}
public static Person Ra(int key = 1)
{
Person[] people = new Person[key];
for (int i = 0; i < key; i++)
{
people[i].number = i + 1;
}
int order = 1;
while (people.Length > 1)
{
for (int i = 0; i < people.Length; order++, i++)
{
people[i].sort = order;
}
//LINQ语言:写法一
//IEnumerable<Person> newPeople = from val in people
// where val.sort % 3 != 0
// select val;
//people = newPeople.ToArray();
//LINQ语言:写法二
people = people.Where(val => val.sort % 3 != 0).ToArray();
}
return people[0];
}
}
三、小陆每天要写一份工作日报,日报标题含有日期。几年后,他翻开以前的日报,想知道两份日报的日期是否同为星期几,请编程帮助他判断。
using System;
struct CompareDate
{
public int year1;
public int month1;
public int day1;
public int week1;
public int year2;
public int month2;
public int day2;
public int week2;
}
class Program
{
public static void Main(string[] str)
{
int group = int.Parse(Console.ReadLine());
CompareDate[] compareDate = new CompareDate[group];
for (int i = 0; i < group; i++)
{
string[] inputs = Console.ReadLine().Split("".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
compareDate[i].year1 = int.Parse(inputs[0]);
compareDate[i].month1 = int.Parse(inputs[1]);
compareDate[i].day1 = int.Parse(inputs[2]);
compareDate[i].year2 = int.Parse(inputs[3]);
compareDate[i].month2 = int.Parse(inputs[4]);
compareDate[i].day2 = int.Parse(inputs[5]);
}
for (int i = 0; i < group; i++)
{
Console.WriteLine($"{Compare(compareDate[i])}");
}
}
public static bool Compare(CompareDate compareDate)
{
compareDate.week1 = WeekValue(compareDate.year1, compareDate.month1, compareDate.day1);
compareDate.week2 = WeekValue(compareDate.year2, compareDate.month2, compareDate.day2);
return compareDate.week1 == compareDate.week2;
}
public static int WeekValue(int year = 0, int month = 0, int day = 0)
{
if (month == 1 || month == 2)
{
month += 12;
year--;
}
int week = (day + 2 * month + 3 * (month + 1) / 5 + year + year / 4 - year / 100 + year / 400) % 7;
return week;
}
}
四、段誉身具凌波微波,动无常则,若危若安,一次能走一级台阶或者两级台阶,他要爬一段30级的山路,问有多少种走法?分析如何计算,然后编程解答。
进阶问题:当他轻功熟练度提升,一次最多可以走三级,那就结果有什么变化?后来走火入魔了,不能走一级,只能走二或三级,又有什么变化?
using System;
class Program
{
public static void Main(string[] str)
{
int hierarchy = int.Parse(Console.ReadLine());
Console.WriteLine($"{Condition1(hierarchy)} {Condition2(hierarchy)} {Condition3(hierarchy)}");
}
public static int Condition1(int hierarchy)
{
if (hierarchy == 0) return 1;
if (hierarchy < 0) return 0;
return Condition1(hierarchy - 1) + Condition1(hierarchy - 2);
}
public static int Condition2(int hierarchy)
{
if (hierarchy == 0) return 1;
if (hierarchy < 0) return 0;
return Condition2(hierarchy - 1) + Condition2(hierarchy - 2) + Condition2(hierarchy - 3);
}
public static int Condition3(int hierarchy)
{
if (hierarchy == 0) return 1;
if (hierarchy < 0) return 0;
return Condition3(hierarchy - 2) + Condition3(hierarchy - 3);
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现