当前位置:网站首页>C # basic 4-written examination question 1
C # basic 4-written examination question 1
2022-07-28 20:54:00 【W.C.Zeng】
Fibonacci Series No n Number
1 1 2 3 5 8 13 Please n Number ?
The simplest recursion , The first two numbers return directly 1 , The next value is returned as the sum of the first two numbers
// recursive 1 1 2 3 5 8 13
static int GetNumber(int n)
{
int ret = 1;
if (n > 2)
{
return GetNumber(n - 1) + GetNumber(n - 2);
}
else
{
return ret;
}
}
Replace the bottle cap with soda
altogether A Yuan Unit purchase price B Soft drink Every time C The lid of a bottle of soda can be exchanged for a bottle of soda How many bottles can I buy ?
Buy soda for the first time and get A/B bottle , The remaining caps A/B individual
For the second time, the bottle cap is not enough C individual , Cannot exchange ; The cap is enough , obtain A/B/C bottle , The remaining caps A/B/C One plus deficiency C Part of A/B%C
static int Buy(int a, int b, int c)
{
return a / b + Cap(c, a / b);
}
// recursive Every time c A lid for a bottle of soda altogether d Covers How much soda can I change ?
static int Cap(int c, int d)
{
// Not enough to exchange for a bottle of soda
if (d < c)
{
return 0;
}
else
{
// Judge whether the subsequent covers can continue to be exchanged d / c It's the bottle I got this time + d % c Exchange the remaining bottle caps this time
return d / c + Cap(c, d / c + d % c);
}
}
Turn on the light
A row of lamps in total n individual , The first person turns on all the lights , The first 2 Personal close all the number 2 Multiple Lights , The first 3 Individuals open all the pages 3 Multiple Lights , The first k One person opens / Close all sections k Multiple , Which lights are finally turned on ?
static void Main()
{
GetLight(100, 100);
}
static void GetLight(int n, int k)
{
// The default is false
bool[] light = new bool[n];
// The first person starts to traverse
for (int i = 1; i <= k; i++)
{
// The first light starts to operate
for (int j = 0; j < n; j++)
{
// Operation No. j Lights j Exactly i Multiple
if ((j+1) % i == 0)
{
light[j] = !light[j];
}
}
}
// Print the results
for (int i = 0; i < n; i++)
{
if (light[i])
Console.WriteLine(i+1);
}
}
Integer output is octal number output
static void Main()
{
d2(10);
}
static void d2(int i)
{
if (i > 7)
{
d2(i / 8);
}
Console.Write(i % 8);
}
Print 200 The prime number within
Prime number : Can only be 1 And divide themselves
static void Main()
{
GetNumber(200);
}
static void GetNumber(int num)
{
int count = 0;
for (int i = 1; i <= num; i++)
{
for (int j = 2; j < i; j++)
{
if (i % j == 0 && i != j)
{
break;
}
if (j == i - 1)
{
count++;
Console.WriteLine(i);
}
}
}
Console.WriteLine("count:" + count);
}
Yang hui triangle
Print 7 Row Yang Hui triangle number Use a two-dimensional array
int[][] a = new int[7][];
for (int i = 0; i < 7; i++)
{
a[i] = new int[i + 1];
a[i][0] = 1;
a[i][i] = 1;
if (i > 1)// Find the intermediate data
{
for (int j = 1; j < i; j++)
{
// Number of current intermediate index positions be equal to The sum of the number at the same index position of the previous row and the previous number
a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
}
}
}
// Print
for (int i = 0; i < a.Length; i++)
{
for (int k = 0; k < a.Length - 1 - i; k++)
{
Console.Write(" ");
}
for (int j = 0; j < a[i].Length; j++)
{
Console.Write(string.Format("{0:00}", a[i][j]));
if (j != a[i].Length - 1)
{
Console.Write(" ");
}
}
Console.WriteLine();
}
The time problem of fishing for three days and drying nets for two days
Suppose the fisherman comes from 2022 year 6 month 1 The date of , Three days fishing and two days net drying , Today is fishing or drying nets ?
Console.WriteLine(DateTime.Now.Day - DateTime.Parse("2022-06-01").Day % 5 < 3 ? " Fishing " : " Basking net ");
边栏推荐
- JS page black and white background switch JS special effect
- UE4 3dui widget translucent rendering blur and ghosting problems
- SQL audit tool self introduction owls
- How can enterprises successfully complete cloud migration?
- [1331. Array serial number conversion]
- 远光软件获得阿里云产品生态集成认证,携手阿里云共建新合作
- Unity typewriter teaches you three ways
- What is "security"? Volvo tells you with its unique understanding and action
- 瀚高数据库最佳实践配置工具HG_BP日志采集内容
- PXE_ KS unattended system
猜你喜欢

Redis的三种删除策略以及逐出算法

第六七八次作业

Unity gets which button (toggle) is selected under togglegroup
About the title of linking to other pages

Laser slam:logo-loam --- code compilation, installation and gazebo test

Unity performance optimization

Teach you unity scene switching progress bar production hand in hand

Unity package project to vs deploy hololens process summary

JS fly into JS special effect pop-up login box

全链路灰度在数据库上我们是怎么做的?
随机推荐
High beam software has obtained Alibaba cloud product ecological integration certification, and is working with Alibaba cloud to build new cooperation
How do we do full link grayscale on the database?
Read the recent trends of okaleido tiger and tap the value and potential behind it
Unity uses shader to quickly make a circular mask
Unity gadget displays the file size of the resource directory
微信小程序的分包加载
Redis review summary
3D laser slam: Interpretation of logo-loam paper - Introduction
Pl515 SOT23-5 single / Dual Port USB charging protocol port controller Parkson electronic agent
Explain mesh Collider in unity
js飞入js特效弹窗登录框
Interpretation of ue4.25 slate source code
算法面试高频题解指南【一】
想画一张版权属于你的图吗?AI作画,你也可以
Record an error in runtime. Getruntime().Exec ("command")
Hangao database best practice configuration tool Hg_ BP log collection content
既要便捷、安全+智能,也要颜值,萤石发布北斗星人脸锁DL30F和极光人脸视频锁Y3000FV
华为云数字资产链,“链”接数字经济无限精彩
激光slam:LeGO-LOAM---代码编译安装与gazebo测试
什么是“安全感”?沃尔沃用它自己独特的理解以及行动来告诉你