恶臭数字之和c++

1 篇文章 1 订阅
1 篇文章 1 订阅

可输入1145141919810以及它的字串,可求得恶臭等式;

欢迎来到化粪池

#include<bits/stdc++.h>
using namespace std;
void zero(){
	cout<<"(1-1)*4514";
}
void positive(int num){
	int cnt=0;
	map<int,string>m;
	m[1]="11/(45-1)*4";
	m[2]="-11+4-5+14";
	m[3]="11*(-4)+51-4";
	m[4]="-11-4+5+14";
	m[5]="11-4*5+14";
	m[6]="1-14+5+14";
	m[7]="11-4+5-1-4";
	m[8]="11-4+5/1-4";
	m[9]="11-4+5+1-4";
	m[10]="-11/4+51/4";
	while (num>0){
		cnt++;
		int ys=num%10;
		if (ys==0){
			num/=10;
			continue;
		}
		else{
			cout<<"("<<m[ys]<<")";
			for (int i=1;i<=cnt-1;i++){
				cout<<"*("<<m[10]<<")";
			}
		}
		if (num>10) cout<<"+";
		num/=10;
	}
}
void negative(int num){
	cout<<"(11/(45-1)*4)*(11-4-5+1-4)*(";
	num=abs(num);
	int cnt=0;
	map<int,string>m;
	m[1]="11/(45-1)*4";
	m[2]="-11+4-5+14";
	m[3]="11*(-4)+51-4";
	m[4]="-11-4+5+14";
	m[5]="11-4*5+14";
	m[6]="1-14+5+14";
	m[7]="11-4+5-1-4";
	m[8]="11-4+5/1-4";
	m[9]="11-4+5+1-4";
	m[10]="-11/4+51/4";
	while (num>0){
		cnt++;
		int ys=num%10;
		if (ys==0){
			num/=10;
			continue;
		}
		else{
			cout<<"("<<m[ys]<<")";
			for (int i=1;i<=cnt-1;i++){
				cout<<"*("<<m[10]<<")";
			}
		}
		if (num>10) cout<<"+";
		num/=10;
	}
	cout<<")";
}
void zhengshu(int zs){
	if (zs>0){
		positive(zs);
	}
	else if (zs<0){
		negative(zs);
	}
	else{
		zero();
	}
}
int main(){
	int n;
	cin>>n;
	cout<<n<<"=";
	zhengshu(n);
	return 0;
}

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值