我不明白为什么它告诉我。如果不困难请解释我。 我使用c ++ 11这个程序应该乘以两个数字并将它们保存在数组中。 我可以重新获得,但它仍然不起作用请有人给出答案。因为它必须有效。如果您有问题,请在下面写下评论。现在可以。谢谢。
#include <iostream>
#include<string.h>
#include<vector>
#include<cmath>
#define MAX 5001
using namespace std;
string multiply(string s , string s1)
{
int res[10000] , a[10000] , b[10000];
int length;
if(s.length() > s1.length())
length = s.length();
else
length = s1.length();
memset(a , 0 , sizeof(a));
memset(b , 0 , sizeof(b));
for(int i = 0;i < 10000;i++)
{
if(i > length)
break;
a[i] = b[i] = 0;
//cout<<s[i] << " " << s1[i]<<endl;
if(i <= (int)s.length())
{
if(i < s.length())
a[i] = int(s[s.length() - i-1]) - 48;
}
if(i <= (int)s1.length())
{
if(i < s1.length())
b[i] = int(s1[s1.length() - i-1])- 48;
}
//cout<<a[i] << " " << b[i] << endl;
}
//cout<<endl;
for(int i = 0;i < length+1;i++)
{
//cout<<a[i] << " " << b[i] << endl;
b[i] += a[i];
b[i+1] += b[i] / 10;
b[i] %= 10;
//cout<<b[i] << " " << a[i] << endl;
}
if(b[length] > 0)
length++;
string rez = "";
for(int i = length-1;i >= 0;i--)
{
rez += char(b[i] + 48);
//cout<<b[i];
}
return rez;
}
bool is(long long n)
{
if(n == 0 || n == 1)
{
return false;
}
if(n == 2)
return true;
for(long long i = 2;i <= sqrt(n);i++)
{
if(n % i == 0)
return false;
}
return true;
}
int main()
{string arr[MAX];
vector<string> coins;
arr[0] = "1";
coins.push_back("2");
int n;
cin>>n;
if(n< 12)
cout<<1/0;
cin.get();
for(int i = 3;i <= 5000;i++)
if(is(i))
coins.push_back(to_string(i));
for(int j = 0;j < (int)coins.size();j++)
{
for(int i = 1;i <= n;i++)
if(i >= atoi(coins[j].c_str()))
arr[i] = multiply(arr[i - atoi(coins[j].c_str())] , arr[i]);
}
cout<<arr[n];
//cout<<multiply("2" , "22");
}