问题一:下面的代码有什么问题
#include <iostream>
using namespace std;
int main()
{
int x;
cin >> x;
int a = 0;
a += x / 33;
x = x % 33;
a += x / 23;
x = x % 23;
a += x / 16;
x = x % 16;
a += x / 5;
x = x % 5;
a += x ;
cout << a <<' ';
int y = x;
int b = 0;
while(y > 0)
{
if(y>=1 && y<5)
{
b ++;
y -= 1;
continue;
}
else if(y>=5 && y<16)
{
b ++;
y -= 5;
continue;
}
else if(y>=16 && y<23)
{
b ++;
y -= 16;
continue;
}
else if(y>=23 && y<33)
{
b ++;
y -= 23;
continue;
}
else
{
b ++;
y -= 33;
continue;
}
}
cout << b ;
return 0;
}
问题二:下面的代码有什么问题
#include <iostream>
using namespace std;
int main()
{
int n,p;
cin >> n >> p;
int m = 1;
for(int i=1;i<=n;i++)
{
m *= i;
}
int a = 0;
while(m % p == 0)
{
m /= p;
a++;
}
cout << a;
return 0;
}
问题三:如何写
问题四:如何写
穷举法要多层循环才行
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int res1=99, res2=0;
int i, j,k,e,u;
for (i = 0; i < 4; i++)
for (j = 0; j < (n - 33 * i) / 23 + 1; j++)
for (k = 0; k < (n - 33 * i - 23 * j) / 16 + 1; k++)
for (e = 0; e < (n - 33 * i - 23 * j - 16 * k)/5 + 1; e++)
for (u = 0; u < n - 33 * i - 23 * j - 16 * k - 5 * e + 1; u++)
if (33 * i + 23 * j + 16 * k + 5 * e + u == n)
if (i + j + k + e + u < res1)
res1 = i + j + k + e + u;
res2 += n / 33;
n = n % 33;
res2 += n / 23;
n = n % 23;
res2 += n / 16;
n = n % 16;
res2 += n / 5;
n = n % 5;
res2 += n;
cout << res1 <<" "<<res2<< endl;
return 0;
}
你应该将你写的代码和题目贴出来,这样好供大家评点,图片的话不方便。将文字、代码贴出来,别人才好在自己电脑中试运行,也方便定位问题。你觉得呢