using System; using System.Collections; using System.Collections.Generic; using System.Text; public class Program { public static void Main() { string line; while ((line = System.Console.ReadLine ()) != null) { // 注意 while 处理多个 case int n = int.Parse(line); StringBuilder sb = new StringBuilder(); //倒推,扭蛋顺序存入sb while(n != 0){ if(n % 2 == 0){ sb.Append("3"); n = (n - 2) / 2; } else{ sb.Append("2"); n = (n - 1) / 2; } } //反转sb StringBuilder result = new StringBuilder(sb.Length); for(int i = sb.Length - 1; i >= 0; i--){ result.Append(sb[i]); } Console.WriteLine(result.ToString()); } } }
从n反推扭蛋顺序,n为偶数则最后一次必是3号扭蛋机,奇数则是2号,一直反推到n=0;