• 题目1 转


    1、有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。

    2、用1、2、2、3、4、5这六个数字,写程序打印出所有不同的排列,如:512234、412345等,要求:"4"不能在第三位,"3"的右边不能是"5"。


    C# code

    public class Program
    {

    public static void Main()
    {
    List<int> list = new List<int>();
    //n=50
    for (int i = 1; i <=50; i++)
    {
    list.Add(i);
    }
    int index = 1;
    int under = 0;
    while (list.Count > 1)
    {
    Console.WriteLine(string.Format("{0}喊了{1}",list[under],index));
    if (index == 3)
    {
    Console.WriteLine(string.Format("{0}被弹出", list[under]));
    Console.Read();
    list.RemoveAt(under);
    under--;
    index = 0;
    }
    if (under == list.Count - 1) under = -1;
    index++;
    under++;

    }
    }
    }


    public class Program
    {

    public static void Main()
    {
    List<string> list = new List<string>();
    list.AddRange(GetString(new string[]{"1","2","2","3","4","5"}));
    list.Sort();//排序,可以看清楚有没有重复
    foreach (string s in list) {
    if (s.IndexOf("4") != 2)
    {
    if(s.IndexOf("35")==-1)
    Console.WriteLine(s);
    }
    }
    }
    static string[] GetString(string[] cs)
    {
    if (cs.Length == 2)
    {
    if (cs[0] == cs[1]) return new string[] { cs[0] + cs[1] };
    return new string[] { cs[0] + cs[1], cs[1] + cs[0] };
    }
    List<string> list = new List<string>();
    bool first = true;
    for (int i = 0; i < cs.Length; i++)
    {
    List<string> tmp = new List<string>(cs);
    tmp.RemoveAt(i);
    if (tmp.IndexOf(cs[i]) != -1 && first) { first = false; continue; }
    string[] sub = GetString(tmp.ToArray());
    List<string> tmp2 = new List<string>();
    foreach (string s in sub)
    {
    tmp2.Add(cs[i] + s);
    }
    list.AddRange(tmp2.ToArray());
    }
    return list.ToArray();
    }

    }

  • 相关阅读:
    Https的请求过程
    计算机网络知识
    数据结构之图
    Python3线程池进程池
    数据结构之堆heapq
    EffectivePython并发及并行
    EffectivePython类与继承
    EffectivePython并发及并行
    5.19完全数
    5.18数字全排列
  • 原文地址:https://www.cnblogs.com/liye/p/1713154.html
Copyright © 2020-2023  润新知