【2022年蓝桥杯】蓝桥杯第一次海选考试题(5题考试大二)(C#题解)
生活随笔
收集整理的這篇文章主要介紹了
【2022年蓝桥杯】蓝桥杯第一次海选考试题(5题考试大二)(C#题解)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
請根據答題情況自己給出分數。
目錄
1.字符串值交換(10分)【變量操作】
2.會員打折(20分)【分支結構】
3.輸出九九乘法表(20分)【循環結構】
4.計算從1開始累加到2^64,測試數據最低10000000(一億)的值,時間不得超過1s。(25分)【規律總結】
5.生兔子問題(25分)【邏輯基礎】
1.字符串值交換(10分)【變量操作】
string x = Console.ReadLine(); string y = Console.ReadLine(); string z = x; x = y; y = z; Console.WriteLine(x); Console.WriteLine(y);2.會員打折(20分)【分支結構】
int x = int.Parse(Console.ReadLine()); double y = double.Parse(Console.ReadLine());if (x == 1 & y >= 0) {if (y >= 500){Console.WriteLine(y * 0.6);}else if (y >= 300){Console.WriteLine(y * 0.65);}else if (y >= 200){Console.WriteLine(y * 0.7);}else if (y >= 100){Console.WriteLine(y * 0.8);}else{Console.WriteLine(y * 0.9);} } else if (x == 0 & y > 0) {if (y >= 100){Console.WriteLine(y * 0.9);}else{Console.WriteLine(y);} } else {Console.WriteLine("x只允許輸入1與0,y必須大于0"); }3.輸出九九乘法表(20分)【循環結構】
for (int i = 1; i < 10; i++) {for (int j = 1; j <= i; j++){Console.Write(j + "*" + i + "=" + (i * j) + "\t");}Console.WriteLine(); }4.計算從1開始累加到2^64,測試數據最低10000000(一億)的值,時間不得超過1s。(25分)【規律總結】
decimal x = decimal.Parse(Console.ReadLine()); Console.WriteLine((x + 1) * x / 2);5.生兔子問題(25分)【邏輯基礎】
有一對兔子,從出生后第四個月起每個月都生一對兔子,小兔子長到第四個月后每個月又生一對兔子。假如兔子都不死,計算第十個月兔子的總數?
解法1:
int month = int.Parse(Console.ReadLine()); int one = 1; int two = 1; int three = 0; for (int i = 1; i < month; i++) {three = two;two = one + two;one = three; } Console.WriteLine(three * 2);解法2:
static int dfs(int i) {if (i==0) {return 0;}if (i == 1) {return 1;}return dfs(i - 1) + dfs(i - 2); } static void Main(string[] args) {int i = dfs(10);Console.WriteLine(i*2); } 與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的【2022年蓝桥杯】蓝桥杯第一次海选考试题(5题考试大二)(C#题解)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java_IO流(精讲)包含练习题及答案
- 下一篇: C#MUD英雄大作战(副源码文件连接)