using System; using System.Collections.Generic; class Program {     static void Main(string[] args)     {         string str;         str = Console.ReadLine();         var t = int.Parse(str);         List<int> nums = new List<int>(t);         for (var i = 0; i < t; ++i)         {             str = Console.ReadLine();             nums.Add(int.Parse(str));         }         nums.ForEach(n =>         {             char[] ss = n.ToString().ToCharArray();             List<int> result = new List<int>();             GetAllRange(ref ss, 0, ref result);             bool possible = false;                 //Console.WriteLine(result.Count);                 foreach (var i in result)             {                     //Console.WriteLine($"{i} mod {n} = {i % n}");                     if (i != n && i % n == 0)                 {                     possible = true;                     break;                 }             };             if (possible)             {                 Console.WriteLine("Possible");             }             else             {                 Console.WriteLine("Impossible");             }         });         Console.ReadKey();     }     static void GetAllRange(ref char[] ss, int k, ref List<int> result)     {         if (k == ss.Length)         {             string s = new string(ss);             result.Add(int.Parse(s));         }         else         {             for (int i = k; i < ss.Length; i++)             {                 Swap(ref ss, k, i);                 GetAllRange(ref ss, k + 1, ref result);                 Swap(ref ss, k, i);             }         }     }     static void Swap(ref char[] ss, int k, int i)     {         char temp = ss[k];         ss[k] = ss[i];         ss[i] = temp;     } } 第一题通过率倒是100%
点赞 评论

相关推荐

牛客网
牛客企业服务