import java.util.Scanner; public class Main{ static int max=-1; public static void main(String[] args) { Scanner s=new Scanner(System.in); int n=s.nextInt(); String str[]=new String[n]; int rs[]=new int[n]; for(int i=0;i<n;i++) { str[i]=s.next(); rs[i]=s.nextInt(); } for(int i=0;i<n;i++) { max=0; f(str[i].substring(1),rs[i],Integer.parseInt(str[i].substring(0,1))); System.out.println(max); } } public static void f(String str,int num,int count) { if(count==num&&str.equals("")) { System.out.println(str); max++; return; } for(int i=0;i<str.length();i++) { int a=Integer.parseInt(str.substring(i, i+1)); for(int j=0;j<2;j++) { if(j==0) { count=count+a; f(str.substring(i+1),num,count); count=count-a; }else { count=count-a; f(str.substring(i+1),num,count); count=count+a; } } } return; } } 第二题为啥不行啊,求教
点赞 评论

相关推荐

06-28 22:48
已编辑
广东金融学院 Java
小浪_Coding:学院本+这俩项目不是buff叠满了嘛
点赞 评论 收藏
分享
07-18 18:05
门头沟学院 Java
挂了&nbsp;正式批求捞
投递滴滴等公司9个岗位
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务