oj 3454 C#组成考题字符串

Valonia ·
更新时间:2024-09-21
· 959 次阅读

题目描述

假定已经获取题库中的试题号,并存放在数组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”。要求,组成考题字符串中考题不重复,输出所有可能的字符串。

输入

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

输出

所有可能的考题字符串;

using System; using System.IO; using System.Globalization; using System.Security.Cryptography; using System.Text; namespace myApp { class Program { static void Main(string[] args) { string s = Console.ReadLine(); int a = int.Parse(s); string s1 = Console.ReadLine(); string[] s2 = s1.Split(' '); int[] b = Array.ConvertAll(s2, int.Parse); Test(b); } public static void Test(int[] arrayKT) { int i = 0; int n = arrayKT.Length ; for (i = n-1; i >=0; i--) { for (int j = 0; j < arrayKT.Length; j++) { if (arrayKT[i] == arrayKT[j]) { i = j; } else { Console.Write("{0} ", arrayKT[j]); } } Console.WriteLine(); } } } }
作者:weixin_46292455



C# 字符串 oj 字符

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