问题 A: c#Helloworld
题目描述
请输出样例所示内容
输出
样例输出
********** Hello,world! **********
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("**********");
Console.WriteLine("Hello,world!");
Console.WriteLine("**********");
Console.ReadKey();
}
}
}
问题 B: 判断闰年
题目描述
使用C#编写一个控制台应用。输入-一个年份,判断是否润年(被4整除,且不被100整除,或者被400整除)。
是闰年输出yes,不是输出no
输入
一个年份
输出
yes或者no
样例输入
copy
1996
样例输出
yes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int s = Convert.ToInt32(Console.ReadLine());
if((s%4==0&&s%100!=0)||s%400==0)
Console.WriteLine("yes");
else
Console.WriteLine("no");
Console.ReadKey();
}
}
}
问题 C: 采用递归求第n位数(c#)
题目描述
一数列的规则如下:1、1、2、3、5、8、13、21、34......。求第n位数是多少?
输入
输入一个正整数,代表求第几位数字
输出
输出第n位数字
样例输入
copy
30
样例输出
832040
提示
输入数字必须大于零
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class digui
{
public int digui_function(int n)
{
if (n == 1||n == 0)
return 1;
else
return digui_function(n - 1)+digui_function(n-2);
}
}
class Program
{
static void Main(string[] args)
{
int s = Convert.ToInt32(Console.ReadLine());
digui r = new digui();
int h=r.digui_function(s-1);
Console.WriteLine(h);
Console.ReadKey();
}
}
}
问题 D: 歌手的分数
题目描述
一青年歌手参加比赛。使用C#编写-一个控制台应用,输入10位评委打分(分值只能为正整数),计算并输出歌手的平均分(去掉一一个最高分和一一个最低分)。平均分以double数据类型输出。
输入
1 2 3 4 5 6 7 8 9 10
输出
5.5
样例输入
copy
1 2 3 4 5 6 7 8 9 10
样例输出
5.5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class grade
{
public int max_function(int m,int n)
{
if (m >= n)
return m;
else
return n;
}
public int min_function(int m,int n)
{
return m <= n ? m : n;
}
}
class Program
{
static void Main(string[] args)
{
int max=-1,i=0,s;
int min=200;
double ans = 0;
string str = Console.ReadLine();
string[] arr = str.Split(' ');
grade r = new grade();
for(i=0;i<10;i++)
{
s = Convert.ToInt32(arr[i]);
max=r.max_function(max, s);
min = r.min_function(min, s);
ans += (double)s;
}
ans = (ans - (double)max - (double)min)/8;
Console.WriteLine(ans);
Console.ReadKey();
}
}
}
问题 E: 冒泡排序算法(C#)
题目描述
使用C#编写一个控制台应用。输入10个整数存入数组中,然后使用冒泡排序算法对一维数组的元素从小到大进行排序,并输出。
输入
在控制台中输入数字,存入一维数组
输出
输出排序后的数组
样例输入
copy
87 85 89 84 76 82 90 79 78 68
样例输出
68 76 78 79 82 84 85 87 89 90
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int [] arr=new int[10];
int i;
for(i=0;i<10;i++)
{
int s = Convert.ToInt32(Console.ReadLine());
arr[i] = s;
}
for (i = 0; i < 10; i++)
{
for (int j = 0; j < 9; j++)
{
if (arr[j] > arr[j + 1])
{
int t = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = t;
}
}
}
for (i = 0; i < 10;i++ )
Console.WriteLine(arr[i]);
Console.ReadKey();
}
}
}
问题 F: 水仙花数
题目描述
春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的: “水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+5^3+3^3。 现在要求输出所有在m和n范围内的水仙花数。
输入
输入数据有多组,每组占一行,包括两个整数m和n(100<=m<=n<=999)。
输出
对于每个测试实例,要求输出所有在给定范围内的水仙花数,就是说,输出的水仙花数必须大于等于 m,并且小于等于n,如果有多个,则要求从小到大排列在一行内输出,之间用一个空格隔开; 如果给定的范围内不存在水仙花数,则输出no; 每个测试实例的输出占一行。
样例输入
copy
100 120 300 380
样例输出
no 370 371
提示
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
/*153 370 371 407*/
class Program
{
static void Main(string[] args)
{
string str;
while(true)//WA了两发,这个多组输入和c/c++不同
{
str = Console.ReadLine();
if (str == null || str.Length <= 0)
break;
string[] s = str.Split(' ');
int n,m,flag1=0,flag2=0,flag3=0,flag4=0;
n = Convert.ToInt32(s[0]);
m = Convert.ToInt32(s[1]);
if (153 >= n && 153 <= m)
{
Console.Write(153);
flag1 = 1;
}
if (370 >= n && 370 <= m)
{
if (flag1 == 1)
Console.Write(" " + 370);
else
Console.Write(370);
flag2 = 1;
}
if (371 >= n && 371 <= m)
{
if (flag2 == 1)
Console.Write(" " + 371);
else
Console.Write(371);
flag3 = 1;
}
if (407 >= n && 407 <= m)
{
if (flag3 == 1)
Console.Write(" " + 407);
else
Console.Write(407);
flag4 = 1;
}
if (flag1 == 0 && flag2 == 0 && flag3 == 0 && flag4 == 0)
Console.Write("no");
Console.WriteLine();
}
}
}
}