奇安信 4.1 前端笔试
第一题AC
import java.util.*; public class Main{ public static int totalsize = 0; public static void main(String[]args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); String[] nlist = sc.nextLine().split(" "); List<List<String>> res = new ArrayList<List<String>>(); List<String> siout = new ArrayList<String>(); for(int i = 0; i< n; i++){ siout.add(nlist[i]); } bt(n,res,siout,0); System.out.println(totalsize); } public static void bt(int s, List<List<String>> res, List<String> siout,int first){ if(first == s){ if(siout.indexOf("A")<siout.indexOf("B")){ totalsize++; int l = siout.size(); int total = 0; for(String le: siout){ total++; if(total<l){ System.out.print(le); System.out.print("-"); } else{ System.out.print(le); } } System.out.print(" "); } } for(int i = first; i< s;i++){ Collections.swap(siout,first,i); bt(s,res,siout,first+1); Collections.swap(siout,first,i); } } }第二题没时间做了。