C#程序设计大赛试题
1 英文单词求复数问题(10 分)
题目描述:请编写一个程序,可以将英语规则名词(不考虑不满足以下规则的英语单词)由单数变成复数。已知规则如下:
- 以辅音字母 y 结尾,则将 y 改成 i,再加 es;
- 以 s,x,ch,sh 结尾,则加 es;
- 以元音 o 结尾,则加 es;
- 其他情况直接加 s。
要求用键盘输入英语规则名词,屏幕输出该名词的复数形式。样例输入:
box
样例输出:
Boxes
代码如下:
class Program
{
static void Main(string[] args)
{
int i = 0;
Console.WriteLine("请输入一个英文单词:");
string s = Console.ReadLine();
int n = s.Length;
char[] arr = new char[n];
foreach(char c in s)
{
arr[i] = c;
i++;
}
switch (arr[n - 1])
{
case 'y':
arr[n - 1] = 'i';
foreach (char c in arr) Console.Write(c);
Console.Write("es");
break;
case 's':
case 'x':
case 'o':
foreach (char c in arr) Console.Write(c);
Console.Write("es");
break;
case 'h':
if (arr[n - 2] == 's' || arr[n - 2] == 'c')
{
foreach (char c in arr) Console.Write(c);
Console.Write("es");
}
else
{
foreach (char c in arr) Console.Write(c);
Console.Write("s");
}
break;
default:
foreach (char c in arr) Console.Write(c);
Console.Write("s");
break;
}
Console.ReadKey();
}
}
- 逆数对问题(20 分)
题目描述:设 A[1…..n]是一个包含 n 个不同数的数组,如果在 i<j 的情况下, 有 A[i]>A[j],则(i,j)就称为 A 中的一个逆序对。
请编写程序,根据用户输入的正整数 n(n>=2)和 n 个不同的数,求出数组 A[n] 的逆序对个数。其中,第一行输入数组包含的元素个数 n,第二行输入 n 个不同的数(以逗号分隔)。
假设有数组 A[10],给数组输入 10 个数,则样例输入:
10
1,2,3,6,4,5,7,8,9,10
样例输出:
2
代码如下:
class Program
{
static void Main(string[] args)
{
int i = 0;
int m = 0;
string s = Console.ReadLine();
int n = int.Parse(s);
int[] arr = new int[n];
string s2 = Console.ReadLine();
string[] arr2 =s2.Split(',', ',');
foreach(string c in arr2)
{
arr[i] = int.Parse(c);
i++;
}
for(int j = 0; j < arr.Length; j++)
{
for(int k = j + 1; k < arr.Length; k++)
{
if (arr[j] > arr[k]) m++;
}
}
Console.WriteLine(m);
Console.ReadKey();
}
}
- 数组排序问题(20 分)
题目描述:输入 30 个数到一个 5 行 6 列的数组,经排序后该数组各元素值按
列从小到大排列,并显示该 2 维数组。请编写程序实现此功能。
样例输入:
1 3 20 11 13 10
2 6 21 12 18 19
5 4 27 14 15 16
7 9 17 22 23 24
8 0 25 26 28 29
样例输出:
0 5 10 15 20 25
1 6 11 16 21 26
2 7 12 17 22 27
3 8 13 18 23 28
4 9 14 19 24 29
代码如下:
class Program
{
static void Main(string[] args)
{
int[,] arr = new int[5,6];
for (int i = 0; i < 5; i++)
{
string s = Console.ReadLine();
string[] arr2 = s.Split(' ');
for(int j = 0; j < 6; j++)
{
arr[i,j] = int.Parse(arr2[j]);
}
}
for (int y =0 ; y < 6; y++)
{
for (int x = 0; x < 5; x++)
{
for (int m = y; m < 6; m++)
{
if (m == y)
{
int n = x;
int b;
for (; n < 5; n++)
{
if (arr[x, y] > arr[n, m])
{
b = arr[x, y];
arr[x, y] = arr[n, m];
arr[n, m] = b;
}
}
}
else
{
int n = 0;
int b;
for (; n < 5; n++)
{
if (arr[x, y] > arr[n, m])
{
b = arr[x, y];
arr[x, y] = arr[n, m];
arr[n, m] = b;
}
}
}
}
}
}
int v = 0;
for(int i = 0; i < 5; i++)
{
for(int j = 0; j < 6; j++)
{
Console.Write(arr[i, j] + " ");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
4.连续正整数问题(20 分)
题目描述:一个正整数有可能可以被表示为 n(n>=2) 个连续正整数之和,如:
15=1+2+3+4+5
15=4+5+6
15=7+8
请编写程序,根据输入的任何一个正整数,找出符合这种要求的所有连续正整数序列。
输入数据:一个正整数,通过键盘输入一个正整数。
输出数据:在标准输出上打印出符合题目描述的全部正整数序列,每行一个序列,每个序列都从该序列的最小正整数开始、以从小到大的顺序打印。如果结果有多个序列,按各序列的最小正整数的大小从小到大打印各序列。此外,序列不允许重复,序列内的整数用一个空格分隔。如果没有符合要求的序列,输出“没有符合要求的序列”。
样例输入:
15
样例输出:
1 2 3 4 5
4 5 6
7 8
样例输入:
16
样例输出:
没有符合要求的序列
5.Windows 资源管理器设计(30 分)
题目描述:使用 C#创建一个 Windows 应用程序,在 Form 内设计一个资源管理器。
功能要求:以树形目录结构显示类似于 Windows 中资源管理器的常用功能。当单击树形目录中的节点时,能在右边显示该文件夹下所有的子文件和文件信息。并且均能够在右边的显示框中,使用快捷菜单(单击右键)实现文件夹的查看(以大图标、小图标、列表、详细信息等方式)、新建、删除、重命名、复制等功能。