YTU_OJ C#组成考题字符串

Tricia ·
更新时间:2024-09-21
· 544 次阅读

C#组成考题字符串 题目描述

假定已经获取题库中的试题号,并存放在数组arrayKT中。例如, int [] arrayKT={10,13,18,19,20,22,30,31}。定义一个静态成员方法,该方法实现从上述数组中随机抽出n(n=arrayKT.Length-1)道考题,并组成一个考题字符串。比如,随机从arrayKT中抽取n题组成考题字符串:“10,13,18,20,22,30,31”。要求,组成考题字符串中考题不重复,输出所有可能的字符串。 

输入

题目的个数
数组中的考题号;

输出

所有可能的考题字符串;

样例输入

copy

5 1 2 3 4 5 样例输出 1 2 3 4 1 2 3 5 1 2 4 5 1 3 4 5 2 3 4 5

 思路:

https://blog.csdn.net/Vit_rose/article/details/51381193

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace nine_week { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string Array = Console.ReadLine(); //把元素读到字符串中 string[] Splitted = Array.Split(' '); //将字符串的空格分隔劈开 int[] arrayKT = new int[Splitted.Length]; for (int i = 0; i < Splitted.Length; i++) //导入到新建的整型数组中 arrayKT[i] = int.Parse(Splitted[i]); int[] res = new int[Splitted.Length]; getKTH(arrayKT,0, res,Splitted.Length-1, Splitted.Length - 1, Splitted.Length); } public static void getKTH(int[] arr, int start, int[] result, int index, int n, int arr_len) { int ct = 0; for (ct = start; ct = 0; j--) Console.Write(arr[result[j]]+" "); Console.WriteLine(); } else getKTH(arr, ct + 1, result, index - 1, n, arr_len); } } } }
作者:Loganer



字符串 C# oj 字符

需要 登录 后方可回复, 如果你还没有账号请 注册新账号