第二次代码
Posted 我心悦你
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第二次代码相关的知识,希望对你有一定的参考价值。
/*2016/3/11 1.题目避免重复/ 2.可定制(数量/打印方式) 3.可以控制下列参数 *是否有乘除法 *是否有括号(最多可支持10个数参与计算) *数值范围 *加减有无负数 *除法有无余数
没有实现括号的运算,加不进去了:( */ #include<iostream> #include<fstream> #include<time.h> #include<stdlib.h> #include<math.h> using namespace std; void main() { ofstream outfile; outfile.open("题目.txt"); int num1,num2,num3,num4,num,c,d,f; char y; int xZ[3]; int range; srand((int)time(0)); // 时间种子 cout<<"选择打印方式:(1代表屏幕,0代表文件):"; cin>>f; cout<<"输入题目的数量:"; cin>>num; cout<<"整数数值范围:(1000以内,100以内,10以内)"; cin>>range; while(range!=10&&range!=100&&range!=1000) { cout<<"请输入10,100,或1000:"; cin>>range; } cout<<"是否有乘除法,有输入1,没有输入0:"; cin>>xZ[0]; cout<<"加减有无负数,有输入1,没有输入0:"; cin>>xZ[1]; if(xZ[0]==1) { cout<<"除法有无余数,有输入1,没有输入0:"; cin>>xZ[2]; } for(int i=0;i<num;i++)//输出题目的循环 { num1=rand()%range; num2=rand()%range; num3=rand()%range; num4=rand()%range; c=1+(int)(4*rand()/(RAND_MAX+1.0)); d=1+(int)(2*rand()/(RAND_MAX+1.0)); if(d%2==0)//随机确定整数运算还是真分数运算 { if(xZ[0]==1)//确定是否有乘除 { if(c%4==0)//除法 { if(xZ[2]==0)//是否有余数 { if(num1%num2==0) { if(f==1) cout<<num1<<"/"<<num2<<"="<<endl; else outfile<<num1<<"/"<<num2<<"="<<endl; } else { while(num1%num2!=0) { num1=rand()%range; num2=rand()%range; } if(f==1) cout<<num1<<"/"<<num2<<"="<<endl; else outfile<<num1<<"/"<<num2<<"="<<endl; } } else { if(f==1) cout<<num1<<"/"<<num2<<"="<<endl; else outfile<<num1<<"/"<<num2<<"="<<endl; } } if(c%4==2)//减法 { if(xZ[1]==0)//是否有负数 { if(num1<num2) { if(f==1) cout<<num2<<"-"<<num1<<"="<<endl; else outfile<<num2<<"-"<<num1<<"="<<endl; } else if(f==1) cout<<num1<<"-"<<num2<<"="<<endl; else outfile<<num1<<"-"<<num2<<"="<<endl; } else if(f==1) cout<<num1<<"-"<<num2<<"="<<endl; else outfile<<num1<<"-"<<num2<<"="<<endl; } if(c%4==1) if(f==1) cout<<num1<<"+"<<num2<<"="<<endl; else outfile<<num1<<"+"<<num2<<"="<<endl; if(c%4==3) if(f==1) cout<<num1<<"*"<<num2<<"="<<endl; else outfile<<num1<<"*"<<num2<<"="<<endl; } else//无乘除 { if(c%2==0)//减法 { if(xZ[1]==0)//是否有负数 { if(num1<num2) { if(f==1) cout<<num2<<"-"<<num1<<"="<<endl; else outfile<<num2<<"-"<<num1<<"="<<endl; } else { if(f==1) cout<<num1<<"-"<<num2<<"="<<endl; else outfile<<num1<<"-"<<num2<<"="<<endl; } } else { if(f==1) cout<<num1<<"-"<<num2<<"="<<endl; else outfile<<num1<<"-"<<num2<<"="<<endl; } } if(c%2==1) { if(f==1) cout<<num1<<"+"<<num2<<"="<<endl; else outfile<<num1<<"+"<<num2<<"="<<endl; } } } else//真分数运算 { switch(c%4)//判断运算符 { case(0):y=‘+‘;break; case(1):y=‘-‘;break; case(2):y=‘*‘;break; case(3):y=‘/‘;break; } if(num1>num2)//判断大小,组合成真分数,并确保分母不为0 { if(f==1) cout<<"("<<num2<<"/"<<num1<<")"; else outfile<<"("<<num2<<"/"<<num1<<")"; } else { if(num2==0) { do{num2=rand()%range;} while(num2==0); } if(f==1) cout<<"("<<num1<<"/"<<num2<<")"; else outfile<<"("<<num1<<"/"<<num2<<")"; } if(f==1) cout<<y; else outfile<<y; if(num3>num4) { if(f==1) cout<<"("<<num4<<"/"<<num4<<")"; else outfile<<"("<<num4<<"/"<<num4<<")"; } else { if(num4==0) { do{num4=rand()%range;} while(num4==0); } if(f==1) cout<<"("<<num3<<"/"<<num4<<")"; else outfile<<"("<<num3<<"/"<<num4<<")"; } if(f==1) cout<<"="<<endl; else outfile<<"="<<endl; } } outfile.close(); }
以上是关于第二次代码的主要内容,如果未能解决你的问题,请参考以下文章
java wicket链接onclick代码在第二次点击时不执行
在使用 FirebaseRecyclerPagingAdapter 时,第二次单击 RecyclerView 中的项目时,片段显示为空