标签:
#include<iostream> #include"string" #include<time.h> using namespace std; string *o; int j=0,js=0; int Rnum(int min,int max ) //randon number (digit) { int random; random=(rand()%(max-min+1))+min; return random; } char Ras(int judgemd )// add subtraction multiplication division operator { int random; char operation; if(judgemd==2)random=Rnum(1,2); else random=Rnum(3,4); switch(random) { case(1):{operation=‘+‘;break;} case(2):{operation=‘-‘;break;} case(3):{operation=‘*‘;break;} case(4):{operation=‘/‘;break;} } return operation; } bool Compare(string str) { bool b=true; for(int i=0;i<j;i++) { if(str==o[i]) b=false; } return b; } void Storage(string str)//string or 邻接表 { o[j]=str; j++; } void Asout (int judgen,int min,int max)// if here is not negaive it is true,else false { int num1,num2,num; char ope; string o=""; num1= Rnum(min,max); num2= Rnum(min,max); ope=Ras(2); if(judgen==2) { if(ope==‘-‘) { if(num1<num2) { num=num1; num1=num2; num2=num; } } } o=num1+ope+num2; if(Compare(o)==true) { Storage(o); js++; } //比较 和储存 cout<<num1<<ope<<num2<<"="<<endl; } void Mdout(int judger,int min,int max)// { int num1,num2,num; char ope; string o; num1= Rnum(min,max); num2= Rnum(min,max); ope=Ras(1); if(judger==2) { if(ope==‘/‘) { num=num1*num2; num1=num; } } o=num1+ope+num2; if(Compare(o)==true) { Storage(o); js++; } //比较 和储存 cout<<num1<<ope<<num2<<"="<<endl; }//没写完 void Asmdout(int judgemd,int judgen,int judger,int min,int max) { if(judgemd==2) { Asout ( judgen, min, max); } else { if(Rnum(1,2)==1) { Asout ( judgen, min, max); } else { Mdout(judger, min, max); } } } void Bracket(int judgemd,int min,int max)//it has braket, randem digit. { int num; string o="",o1; num=Rnum(3,10); int *bnum; char *bope; bnum= new int[num]; bope=new char[num-1]; for(int i=0;i<num;i++) { bnum[i]=Rnum(min,max); } for(int i=0;i<num-1;i++) { bope[i]=Ras(Rnum(1,2)); } cout<<"("; for(int i=0;i<num;i++) { cout<<bnum[i]; if(i==2){cout<<")";} if(i==num-1){break;} cout<<bope[i]; } js++; cout<<"="<<endl; } void main() { srand(time(NULL)); int judgeb,judgemd,judgen,judger=2,min,max,n; cout<<"Do you want multiplication and division? 1.Yes 2.No"<<endl; cin>>judgemd; cout<<"Do you want bracket? 1.Yes 2.No"<<endl; cin>>judgeb; if(judgeb==2) { cout<<"Do you want negative? 1.Yes 2.No"<<endl; cin>>judgen; if(judgemd==1) { cout<<"Do you want remainder? 1.Yes 2.No"<<endl; cin>>judger; } } cout<<"which is the scope of the number? input the min and max"<<endl; cin>>min>>max; cout<<"数量"<<endl; cin>>n; o=new string[n]; while(js<n) { if(judgeb==1){ Bracket(judgemd, min, max);}; if(judgeb==2){Asmdout(judgemd, judgen, judger, min, max);}; } }
1. 有乘除有括号
2. 有乘除没括号没负数没余数
3. 没乘除没括号有负数
4.没乘除没括号没负数
5. 大上限
6. 负下限
标签:
原文地址:http://www.cnblogs.com/zuhaoran/p/5323838.html