神奇算式c语言,蓝桥杯——神奇算式(相乘与结果同数)

垃圾代码。。。暴力解法。。。

题目:

56ad1faafc3edd5d6d7e2e9fca8d3f45.png

#include

#include

#include

#include

#include

using namespace std;

bool same(string s1, string s2) {//判断两个字符串内的字符是否完全相同

if (s1.length() != s2.length()) return false;

int len = s1.length();

char *c1 = new char[len+1];//为了使数组范围是变量,用new动态申请

char *c2 = new char[len+1];

strcpy(c1, s1.c_str());//

strcpy(c2, s2.c_str());

sort(c1, c1 + len);//用sort的时候要传入字符数组类型的首地址和尾地址,

sort(c2, c2 + len);

int i, j;

for (i = 0, j = 0; i

if (c1[i] != c2[j])return false;

}

free(c1);

free(c2);

return true;

}

void i2s(int n,string &s){//数字转字符串

stringstream ss;

ss<

ss>>s;

}

int main(int argc, char *argv[]) {

int cnt=0;

for(int i=1;i<=9;i++){

for(int j=0;j<10;j++){

if(i!=j)

for(int k=0;k<10;k++){

if(k!=i&&k!=j)

for(int l=0;l<10;l++)

if(l!=k&&l!=i&&l!=j){//4位数 乘号可能插在三个地方

string s1,s2,s3,so;

i2s(i*(j*100+k*10+l),s1);

i2s((i*10+j)*(k*10+l),s2);

i2s((i*100+j*10+k)*l,s3);

i2s(i*1000+j*100+k*10+l,so);

if(same(s1,so))cnt++;

if(same(s2,so))cnt++;

if(same(s3,so))cnt++;

}

}

}

}

cout<

return 0;

}

eea8c5cc47f40e0ba5555862c3881bf3.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值