本帖最后由 PercyDan 于 2021-1-30 22:13 编辑
我又来了

运行:https://c.runoob.com/compile/14
复制代码
我又来了

运行:https://c.runoob.com/compile/14
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- //尝试次数
- int times = 1;
- //目标句子列表
- List<string> target = new List<string> { "心也可以清", "清心也可以", "以清心也可", "可以清心也" };
- string str = string.Empty;
- while (true)
- {
- str = string.Empty;
- //所有字符的列表
- var chars = new List<char> { '可', '以', '清', '心', '也' };
- for(int i = 0; i < 5; i++)
- {
- //在列表里随机每次抽取一个字组成句子
- int random = new Random().Next(chars.Count);
- //列表为空则跳出循环
- if (chars.Count == 0) continue;
- str += chars[random].ToString();
- //将随机到的字移出列表,防止重复
- chars.RemoveAt(random);
- }
- //如果所有目标句子都已经出现过退出
- if (target.Count == 0) break;
- //当前组成的句子是否符合任意一个目标句子
- if(target.Any(s => s == str))
- {
- //显示结果
- Console.WriteLine($"{str}\t用了{times}次");
- //移出列表,防止重复
- target.Remove(str);
- }
- times++;
- }
- }
- }
- }
美味的曲奇 发表于 2021-1-30 20:36
(我的书的资源包里有个)
用不用发你一份,万一成功了呢
我现在没有电脑你发了也没用
PercyDan 发表于 2021-1-30 20:58
为啥不看我的草
(求个置顶
你的草很枯萎(bushi
什么东西 本来就想水一波 没想到这么高深
Wullll 发表于 2021-1-30 22:20
什么东西 本来就想水一波 没想到这么高深
这有什么高深的?
美味的曲奇 发表于 2021-1-30 22:29
你在想什么奇怪的东西是这种资料
没错就是这种啊