1 #include<iostream> 2 #include<fstream> 3 #include<stdlib.h> 4 #include<string> 5 #include<stdio.h> 6 using namespace std; 7 #define N 100 8 9 void main() 10 { 11 int i,x,y,z,b,fanwei,n1,n2,n3; 12 int c0,c1,c2,c3,c4,c5,c6,c7,c8,c9; 13 char t0[20],t1[20],t2[20],t3[20],t4[20],t5[20],t6[20],t7[20],t8[20],t9[20]; 14 string x0,x1,x2,x3,x4,x5,x6,x7,x8,x9; 15 cout<<"请输入题目的数量:"<<endl; 16 cin>>b; 17 cout<<"请输入数值范围:"<<endl; 18 cin>>fanwei; 19 cout<<"请选择输出方式(屏幕/打印):(1/0)"<<endl; 20 cin>>z; 21 if(z==1) 22 { 23 for(i=0;i<b;i++) 24 { 25 n1=rand()%4; 26 char a[N]={‘+‘,‘-‘,‘*‘,‘/‘}; 27 x=rand()%10; 28 y=rand()%3; 29 int yone=rand()%3; 30 int ytwo=rand()%3; 31 int ythree=rand()%3; 32 int yfour=rand()%3; 33 int yfive=rand()%3; 34 int ysix=rand()%3; 35 36 c0=rand()%fanwei;itoa(c0,t0,10);string z0=t0; 37 c1=rand()%fanwei;itoa(c1,t1,10);string z1=t1; 38 c2=rand()%fanwei;itoa(c2,t2,10);string z2=t2; 39 c3=rand()%fanwei;itoa(c3,t3,10);string z3=t3; 40 c4=rand()%fanwei;itoa(c4,t4,10);string z4=t4; 41 c5=rand()%fanwei;itoa(c5,t5,10);string z5=t5; 42 c6=rand()%fanwei;itoa(c6,t6,10);string z6=t6; 43 c7=rand()%fanwei;itoa(c7,t7,10);string z7=t7; 44 c8=rand()%fanwei;itoa(c8,t8,10);string z8=t8; 45 c9=rand()%fanwei;itoa(c9,t9,10);string z9=t9; 46 x0=z0+a[n1]+z1; 47 switch(y){ 48 case 0: 49 {x1=‘(‘+x0+‘)‘+a[n1]+z2;break;} 50 case 1: 51 {x1=z2+a[n1]+‘(‘+x0+‘)‘;break;} 52 case 3: 53 {x1=x0+a[n1]+z2;break;} 54 } 55 switch(yone){ 56 case 0: 57 {x2=‘(‘+x1+‘)‘+a[n1]+z3;break;} 58 case 1: 59 {x2=z3+a[n1]+‘(‘+x1+‘)‘;break;} 60 case 2: 61 {x2=z3+a[n1]+x1;break;} 62 } 63 switch(ytwo){ 64 case 0: 65 {x3=‘(‘+x2+‘)‘+a[n1]+z4;break;} 66 case 1: 67 {x3=z4+a[n1]+‘(‘+x2+‘)‘;break;} 68 case 2: 69 {x3=z4+a[n1]+x2;break;} 70 } 71 switch(ythree){ 72 case 0: 73 {x4=‘(‘+x3+‘)‘+a[n1]+z5;break;} 74 case 1: 75 {x4=z5+a[n1]+‘(‘+x3+‘)‘;break;} 76 case 2: 77 {x4=z5+a[n1]+x3;break;} 78 } 79 switch(yfour){ 80 case 0: 81 {x5=‘(‘+x4+‘)‘+a[n1]+z6;break;} 82 case 1: 83 {x5=z6+a[n1]+‘(‘+x4+‘)‘;break;} 84 case 2: 85 {x5=z6+a[n1]+x4;break;} 86 } 87 switch(yfive){ 88 case 0: 89 {x6=‘(‘+x5+‘)‘+a[n1]+z7;break;} 90 case 1: 91 {x6=z7+a[n1]+‘(‘+x5+‘)‘;break;} 92 case 2: 93 {x6=z7+a[n1]+x5;break;} 94 } 95 switch(ysix){ 96 case 0: 97 {x7=‘(‘+x6+‘)‘+a[n1]+z8;break;} 98 case 1: 99 {x7=z8+a[n1]+‘(‘+x6+‘)‘;break;} 100 case 2: 101 {x7=z8+a[n1]+x6;break;} 102 } 103 104 105 n2=rand()%3; 106 switch(x){ 107 case 0: 108 {i=i-1;break;} 109 case 1: 110 {i=i-1;break;} 111 case 2: 112 {x0=z0+a[n1]+z1; 113 cout<<x0<<endl;break;} 114 case 3: 115 { 116 if(n2==2) 117 {x1=‘(‘+x0+‘)‘+a[n1]+z2; 118 cout<<x1<<endl;break;} 119 if(n2==1) 120 {x1=z2+a[n1]+‘(‘+x0+‘)‘; 121 cout<<x1<<endl;break;} 122 if(n2==0) 123 {x1=x0+a[n1]+z2; 124 cout<<x1<<endl;break;} 125 } 126 case 4: 127 { 128 if(n2==2) 129 {x2=‘(‘+x1+‘)‘+a[n1]+z3; 130 cout<<x2<<endl;break;} 131 if(n2==1) 132 {x2=z3+a[n1]+‘(‘+x1+‘)‘; 133 cout<<x2<<endl;break;} 134 if(n2==0) 135 {x2=z3+a[n1]+x1; 136 cout<<x2<<endl;break;} 137 } 138 case 5: 139 { 140 if(n2==2) 141 {x3=‘(‘+x2+‘)‘+a[n1]+z4; 142 cout<<x3<<endl;break;} 143 if(n2==1) 144 {x3=z4+a[n1]+‘(‘+x2+‘)‘; 145 cout<<x3<<endl;break;} 146 if(n2==0) 147 {x3=z4+a[n1]+x2; 148 cout<<x3<<endl;break;} 149 } 150 case 6: 151 { 152 if(n2==2) 153 {x4=‘(‘+x3+‘)‘+a[n1]+z5; 154 cout<<x4<<endl;break;} 155 if(n2==1) 156 {x4=z5+a[n1]+‘(‘+x3+‘)‘; 157 cout<<x4<<endl;break;} 158 if(n2==0) 159 {x4=z5+a[n1]+x3; 160 cout<<x4<<endl;break;} 161 } 162 case 7: 163 { 164 if(n2==2) 165 {x5=‘(‘+x4+‘)‘+a[n1]+z6; 166 cout<<x5<<endl;break;} 167 else if(n2==1) 168 {x5=z6+a[n1]+‘(‘+x4+‘)‘; 169 cout<<x5<<endl;break;} 170 else if(n2==0) 171 {x5=x4+a[n1]+z6; 172 cout<<x5<<endl;break;} 173 } 174 case 8: 175 { 176 if(n2==2) 177 {x6=‘(‘+x5+‘)‘+a[n1]+z7; 178 cout<<x6<<endl;break;} 179 if(n2==1) 180 {x6=z7+a[n1]+‘(‘+x5+‘)‘; 181 cout<<x6<<endl;break;} 182 if(n2==0) 183 {x6=x5+a[n1]+z7; 184 cout<<x6<<endl;break;} 185 } 186 case 9: 187 { 188 if(n2==2) 189 {x7=‘(‘+x6+‘)‘+a[n1]+z8; 190 cout<<x7<<endl;break;} 191 if(n2==1) 192 {x7=z8+a[n1]+‘(‘+x6+‘)‘; 193 cout<<x7<<endl;break;} 194 if(n2==0) 195 {x7=x6+a[n1]+z8; 196 cout<<x7<<endl;break;} 197 } 198 } 199 } 200 } 201 } 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
时间: 2024-10-25 12:52:45