用枚举法填运算符
来源:互联网 发布:nginx cc攻击防御 编辑:程序博客网 时间:2024/06/04 23:25
演示一个 5 ? 5?5?5?=5
import java.util.*; public class Text1{public static void main(String[]args){int j ;//循环变量int []type=new int[5];//类加运算符的样式int sign;//保存运算的正负号int result;//结果int count=0;//数量int []num=new int[6];//保存数组float left , right;保存中间值,left保存+-运算的值right保存*/运算值char []oper=new char[]{' ','+','-','*','/'};System.out.println("请输入五个数");for(j=1 ;j<=5 ;j++ ){num[j]=new Scanner(System.in).nextInt();}System.out.println("请输出结果");result = new Scanner(System.in).nextInt();for(type[1]=1 ;type[1]<=4 ;type[1]++ ){if((type[1]<4) || (num[2]!=0)){for( type[2]=1 ;type[2]<=4 ;type[2]++ ){if((type[2]<4) || (num[3]!=0)){for( type[3]=1 ;type[3]<=4 ;type[3]++ ){if((type[3]<4) || (num[4]!=0)){for( type[4]=1 ;type[4]<=4 ;type[4]++ ){if((type[4]<4) || (num[5]!=0)){left=0;right = num[1];sign = 1;for(j=1 ;j<=4 ;j++ ){//System.out.print(oper[type[4]]+" ");switch(oper[type[j]]){case '+':{left = left+sign*right;sign=1;right = num[j+1];break;}case '-':{left = left+sign*right;sign=-1;right = num[j+1];break;}case '*':{right =right*num[j+1];break;}case '/':{right = right/num[j+1];break;}}}if((left+sign*right)==result){count++;System.out.print(count+":");for(j=1 ; j<=4;j++ ){System.out.print(num[j]+""+oper[type[j]]);}System.out.println(num[5]+"="+result);}}}}}}}}}} }
0 0
- 用枚举法填运算符
- 枚举法填运算符
- 枚举法-填数
- 穷举法:填运算符游戏
- 【程序5】填运算符
- 【程序5】填运算符
- 填加减运算符算法
- 枚举法——填写运算符
- 填运算符(C语言)
- 趣味算法-巧填运算符
- PHP填坑——运算符
- [填坑]重载运算符自用总结
- 蓝桥杯 填符号凑算式 趣味运算 DFS枚举 字符串处理
- 算法学习(1)枚举法求运算符
- 三目运算符?:填在数据绑定中
- uva 10400 Game Show Math (填合适的运算符)
- poj1753高斯消元法和位运算枚举法。
- C++中枚举类型++运算符重载
- http线程池的设计与实现(c++)
- spring事务
- sql server数据库中存储过程实现跨数据库定时抓取数据
- 数字签名过程
- mongoDB的读书笔记(04)_【Replica】(02)_Priority 0、Hidden、Delayed Replica Set Members的相关概念
- 用枚举法填运算符
- O2O模式点餐平台哪家强?
- 解决oracle取日期到页面为英文格式的问题
- Go语言的初步认识
- 设计模式——模板方法
- Android 顶部轮播 JazzyViewPager 改变滑动速度
- String转换为Timestamp
- JVM加载class文件的原理机制
- 多线程中的锁系统(一)-基础用法