#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int vis[10]={1,2,3,4,5,6,7,8,9};
int ans=0;
void f(int cur,char *a,string s)
{
if(cur==8)
{
//for(int i=0;i<8;i++){
// cout<<a[i]<<".";}
// ans++;
//cout<<endl;
int sum=0;
string o;
for(int i=0;i<8;i++)
{
/*if((a[i]==' ')&&cnt==0) {s=s+(char)(vis[i]+'0')+(char)(vis[i+1]+'0'); cnt++;}
else if((a[i]==' ')&&cnt!=0) s=s+(char)(vis[i+1]+'0');
else {
s=s+' ';
if(i==0) s=s+(char)(vis[i]+'0');
else {s=s+(char)(vis[i+1]+'0');
cnt=0;
}
}*/
if(i==0) s=s+(char)(vis[i]+'0')+a[i]+(char)(vis[i+1]+'0');
else s=s+a[i]+(char)(vis[i+1]+'0');
}
for(int i=0;i<s.length();i++)
{
if(s[i]!=' ') o=o+s[i];
}
/*int j=0,k=0;
string c;
int cc[10];
for(int i=0;i<o.length();i++)
{
j=i;
if(s[i]>'9'&&s[i]<'0')
{
c=o.substr(k,j-1);
sscanf(c.c_str(),"%d",&x);
cc[y++]=x;
k=j+1;
}
}
c=o.substr(k,8);
sscanf(c.c_str(),"%d",&x);
cc[y++]=x;
for(int i=0;i<y;i++)
cout<<cc[i]<<" ";
cout<<endl;
y=1;
sum=cc[0];
for(int i=0;i<o.length();i++)
{
if(o[i]=='+') sum=sum+cc[y++];
else sum=sum-cc[y++];
}*/
//cout<<o<<endl;
//cout<<s<<endl;
/*for(int i=0;i<8;i++)
{
if(a[i]!=' ') x[j++]=a[i];
}
j=0;
stringstream ss(s);
while(ss>>buf)
{
if(a[j]=='+') sum=sum+buf;
else sum=sum-buf;
j++;
}
j=0;
for(int i=1;i<(int)s.length();i++)
{
if(s[i]==' ') s[i]=a[j++];
//cout<<s<<endl;
}*/
string h;
for(int i=0;i<o.length();i++)
{
if(o[i]<='9'&&o[i]>='1') h=h+o[i];
else h=h+' ';
}
//cout<<h<<endl;
char n[10];
int y=0;
for(int i=0;i<o.length();i++)
{
if(o[i]=='+'||o[i]=='-') n[y++]=o[i];
}
//for(int i=0;i<y;i++)
// cout<<n[i]<<" ";
//cout<<endl;
stringstream ss(h);
int buf;
int ans=0;
y=0;
//cout<<h<<endl;
while(ss>>buf)
{
if(ans==0){sum=sum+buf;ans++;}
else
{
if(n[y]=='+') sum=sum+buf;
else sum=sum-buf;
y++;
}
}
if(sum==110) {cout<<o<<endl;} //cout<<sum<<endl;
return ;
}
a[cur]=' ';
f(cur+1,a,s);
a[cur]='+';
f(cur+1,a,s);
a[cur]='-';
f(cur+1,a,s);
}
int main()
{
/*int a=1;
int buf;
int sum=0;
char c='+';
string x;
string q;
x=x+(char)(a+'0');
x=x+c;
cout<<x<<endl;
x=x.substr(0,1);
cout<<x+(char)(1+'0')<<endl;
q=(char)(1+'0');
q=q+' ';
q=q+(char)(2+'0');
cout<<q<<endl;
stringstream ss(q);
while(ss>>buf) {sum=sum+buf;}
cout<<sum<<endl;*/
string s;
char a[8];
f(0,a,s);
/*string s="1234";
int x;
sscanf(s.c_str(),"%d",&x);
cout<<x<<endl;*/
return 0;
}
趣味算式填符号
最新推荐文章于 2019-03-14 19:38:07 发布