博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
蓝桥杯——神奇算式(相乘与结果同数)
阅读量:7029 次
发布时间:2019-06-28

本文共 1026 字,大约阅读时间需要 3 分钟。

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

题目:

#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
>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<

  

 

转载于:https://www.cnblogs.com/ZengWeiHao/p/10497898.html

你可能感兴趣的文章
Tutorial: Getting Started with SignalR (C#) -摘自网络
查看>>
MSSQL数据库迁移到Oracle(二)
查看>>
S3C2440触摸屏控制总结
查看>>
视频文件格式
查看>>
文件异步上传方式(一)
查看>>
funny alphabet
查看>>
STL队列 之FIFO队列(queue)、优先队列(priority_queue)、双端队列(deque)
查看>>
Android压力测试工具——Monkey
查看>>
使用“DiskGenius”精确隐藏硬盘坏道
查看>>
我心中的核心组件(可插拔的AOP)~第十二回 IoC组件Unity
查看>>
Spring3系列4-多个配置文件的整合
查看>>
SQLServer2005重建索引前后对比【转】
查看>>
Inode详解
查看>>
jquery加入收藏代码
查看>>
7z命令行工具
查看>>
AutoCompleteTextView 与sqlite绑定实现记住用户输入的内容并自动提示
查看>>
Makefile 中会在多处地方看到 FORCE
查看>>
hadoop参数传递
查看>>
揭秘uc浏览器四
查看>>
用条件注释判断浏览器版本,解决兼容问题
查看>>