📄 app.cpp
字号:
#include <iostream>
#include <string>
using namespace std;
struct result
{
int a;
int b;
string r;
};
int main()
{
string sample[1000];
char * s = new char[1000];
int count=0;
int lineCount=0;
int * arrayList = new int[100000];
int * arrayListCopy = new int[100000];
result * Result = new result[1000];
cout<<"第一步,集合元素个数:"<<endl;
cin>>count;
cout<<"第二步,请输入详细:"<<endl;
cin.sync();//清空输入缓存
//获取第二步的输入字符串
for(int i=0;;i++)
{
getline(cin,sample[i]);
if(sample[i]=="0 0")
{
lineCount = i;
//cout<<"haha"<<endl;
break;
}
}
//第一行string转换为int数组(输入的数组)
s=(char *)sample[0].c_str();
for(int j=0,start=0,end=0,arrayNum=0;j<sample[0].length()+1;j++)
{
if((s[j]-'0')==-16||(s[j]-'0')==-48)
{
//cout<<"空格"<<endl;
end = j;
arrayList[arrayNum] = 0;
while(start<end)
{
arrayList[arrayNum] = arrayList[arrayNum]*10+(s[start]-'0');
start++;
}
arrayNum++;
start++;
}
}
//获取其他行数据
for(int w=0;w<lineCount-1;w++)
{
s=(char *)sample[w+1].c_str();
for(int k=0,start=0,end=0;k<sample[w+1].length()+1;k++)
{
if((s[k]-'0')==-4)
{
end=k;
Result[w].a = 0;
while(start<end)
{
Result[w].a = Result[w].a*10+(s[start]-'0');
start++;
}
start++;
}
if((s[k]-'0')==-48)
{
end=k;
Result[w].b = 0;
while(start<end)
{
Result[w].b = Result[w].b*10+(s[start]-'0');
start++;
}
}
else
{
//cout<<"hhhhhhh"<<endl;
}
}
}
for(int h=0;h<count;h++)
arrayListCopy[h]=arrayList[h];
for(int e=0;e<lineCount-1;e++)
{
int count2 = count;
for(int h=1,c=count;h<Result[i].b;h++)
{
//for(int k=0,c=count;k<count;k++)
for(int t=0;t<count2;t++)
{
for(int m=0;m<count;m++)
arrayListCopy[c++]=arrayListCopy[t]+arrayList[m];
}
count2 = c;
}
for(int q=0;q<count2;q++)
{
if(arrayListCopy[q]==Result[e].a)
{
Result[e].r="yes";
break;
}
else
Result[e].r="no";
//cout<<arrayListCopy[j]<<" ";
}
//cout<<endl;
}
//测试输出
cout<<endl;
cout<<"输入数组为:"<<endl;
for(int g=0;g<count;g++)
{
cout<<arrayList[g]<<" ";
}
cout<<endl;
cout<<"计算结果为:"<<endl;
for(int d=0;d<lineCount-1;d++)
cout<<"M:"<<Result[d].a<<" k:"<<Result[d].b<<" 是否能计算出M:"<<Result[i].r<<endl;
system("pause");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -