谁给推荐个带高清视频、像质又好、外形有q、最好还有3X-5X+变焦的小数码?# PhotoGear - 摄影器材
a*y
1 楼
you are given nos 1,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 u hav to form a 9 digit no such
dat 1st 2 digits are divisible by 2,1st 3 digits are divisible by 3,1st 4
digits are divisible by 4 and so on..... (repetitions not allowed)
但是我觉得那个最后fail的情况我return -1 不太好,这样即使fail了还会再在这个错
的上面try组合,虽然我让他即使退出了,但是还会有函数调用在stack上,还有怎么能
让这个函数return那个正确的值哪?本体只有一个正确的值
int GenerateNumber(string input, int digit, bool used[],int number, int n)
{
int temp = 0;
//early termination if failed
int numbeofdigit = 0;
int tempnumber = number;
while (tempnumber)
{
tempnumber /= 10;
numbeofdigit++;
}
if (numbeofdigit < digit)
return -1;
if (digit == 9)
{
cout << number<< endl;
return number;
}
for (int i = 0; i {
if (!used[i])
{
if (digit >= 1)
{
if ((number*10 + (input[i] - '0'))%(digit+1) == 0)
{
int total = number*10 + (int)(input[i] - '0');
used[i] = true;
temp = GenerateNumber(input, digit+1, used, total,n);
used[i] = false;
}
}
else
{
int total = number * 10 + (int)(input[i] - '0');
used[i] = true;
temp = GenerateNumber(input, digit+1, used, total,n);
used[i] = false;
}
}
}
return -1;
}
dat 1st 2 digits are divisible by 2,1st 3 digits are divisible by 3,1st 4
digits are divisible by 4 and so on..... (repetitions not allowed)
但是我觉得那个最后fail的情况我return -1 不太好,这样即使fail了还会再在这个错
的上面try组合,虽然我让他即使退出了,但是还会有函数调用在stack上,还有怎么能
让这个函数return那个正确的值哪?本体只有一个正确的值
int GenerateNumber(string input, int digit, bool used[],int number, int n)
{
int temp = 0;
//early termination if failed
int numbeofdigit = 0;
int tempnumber = number;
while (tempnumber)
{
tempnumber /= 10;
numbeofdigit++;
}
if (numbeofdigit < digit)
return -1;
if (digit == 9)
{
cout << number<< endl;
return number;
}
for (int i = 0; i
if (!used[i])
{
if (digit >= 1)
{
if ((number*10 + (input[i] - '0'))%(digit+1) == 0)
{
int total = number*10 + (int)(input[i] - '0');
used[i] = true;
temp = GenerateNumber(input, digit+1, used, total,n);
used[i] = false;
}
}
else
{
int total = number * 10 + (int)(input[i] - '0');
used[i] = true;
temp = GenerateNumber(input, digit+1, used, total,n);
used[i] = false;
}
}
}
return -1;
}