<一道题>abc+cba=1333,求满足条件的abc的值,隐含条件a!=0,c!=0
2024-10-11 11:01:27
这类东西,无非就是穷举法。见下面代码:
#include <stdio.h>
#include <stdlib.h> /*
*abc + cba = 1333
*
*a = ?
*b = ?
*c = ?
*/ int main(int argc ,char **argv)
{
int a=;
int b=;
int c=; int index = ; printf("abc + cba == 1333\n"); for(a = ; a <= ; a++)//a [1,9]
{
for(b = ; b <= ; b++)//b [0,9]
{
for(c = ; c <= ; c++)//c [1,9]
{
if( == (*a + *b + c + *c + *b + a))
{
index++;
printf("I have found it !!! index : %d , a= %d, b= %d, c=%d\n",index,a,b,c);//多谢1楼仁兄,找到了,却没有注意英文语法,已改found及I }
}
}
} printf("find over\n");
return ;
}
运行结果;
tiger@ubuntu:/mnt/hgfs/e/Lessons/MyExercise/UtilLibs/EXERCISE$ ./abc
abc + cba == 1333
I have found it !!! index : 1 , a= 4, b= 1, c=9
I have found it !!! index : 2 , a= 5, b= 1, c=8
I have found it !!! index : 3 , a= 6, b= 1, c=7
I have found it !!! index : 4 , a= 7, b= 1, c=6
I have found it !!! index : 5 , a= 8, b= 1, c=5
I have found it !!! index : 6 , a= 9, b= 1, c=4
find over
tiger@ubuntu:/mnt/hgfs/e/Lessons/MyExercise/UtilLibs/EXERCISE$
最新文章
- Solr5 DataImport 处理1对多关系
- 【转】敏捷开发 Scrum 总结
- jquery仿天猫商城左侧导航菜单
- HttpClient使用笔记
- cf442C Artem and Array
- MySQL学习笔记(2)
- Hdu 5256 系列转换
- windows下使用git管理github项目
- Linux文件属性上
- ubuntu安装pycharm桌面快捷方式
- java quartz 计算近20次执行时间
- [转]快速新建简单的koa2后端服务
- 关于Java方法重载
- linux 下导出oracle数据库
- 【杂谈】Tomcat 之 Lifecycle接口
- centos7环境安装ElasticSearch
- Win7下VB6.0不能加载mscomctl.ocx的解决办法
- (原创)结构体自动化转为char数组的实现
- MacBook常用软件
- 解题:洛谷4314 CPU监控