为什么一直总是33.3分呢?运行也没有超时,我拿了数据自己测试也没有问题啊,而且拿的就是系统上说的出错的数据,自己测试没有问题,但是系统测试就是说我错了,求大佬赐教,无比感激!!!!!!
import java.util.Scanner;
public class Main {
// public static int c = 0;
public static int count = 0;
public static int N;
static int n1=0,n2=0,n3=0;
public static void test(int[] date)
{
for(int i = 1 ;i < 7;i++)
{
n1 = toInt(date, 0, i);//n1 + n2/n3
if(n1>=N)return;
for(int j = 1;j <9-i;j++)
{
n2 = toInt(date, i, j);
n3 = toInt(date, i+j, 9-i-j);
if(n2%n3!=0)continue;
if(n1+n2/n3 == N)count++;
}
}
}
public static int toInt(int[] date,int start,int w) {
int num = 0;
for(int i = start;i<start+w;i++)
{
num = num*10+date[i];
}
return num;
}
public static void f(int[] date,int k)
{
if(k>=date.length)
{
test(date);
// c++;
return;
}
for(int i = k;i < date.length;i++)
{
{int c = date[k];date[k] = date[i];date[i]=c;}
f(date, k+1);
{int c = date[k];date[k] = date[i];date[i]=c;}
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
int[] date = {1,2,3,4,5,6,7,8,9};
sc.nextLine();
f(date,0);
System.out.println(count);
// System.out.println(c);
}
}