标签:
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <time.h> 4 #include <iomanip> 5 #include <iostream> 6 using namespace std; 7 8 9 10 int main(void) 11 { 12 srand((unsigned)time(NULL)); //本地时间为种子 13 int a[100]; 14 int b[100]; 15 int c[100]; 16 int num; 17 int j; 18 int count; 19 char choice; 20 int jiange; 21 int range; 22 char zhengfu; 23 24 //printf("please input num for type : "); 25 //scanf_s("%d", &num); 26 //printf("please input num for the sum of task : "); 27 //scanf_s("%d", &count); 28 //printf("chose have(y) or not(n) Multiplication and division:"); 29 //scanf_s("%c", &choice); 30 //printf("please input num for jiange :"); 31 //scanf_s("%d", &jiange); 32 cout << "输入每行题目数 : "; 33 cin >> num; 34 cout << "输入题目数 : "; 35 cin >> count; 36 cout << "是否支持乘除(y/n):"; 37 cin >> choice; 38 cout << "输入题与题的间隔 :"; 39 cin >> jiange; 40 cout << "输入生成题目的范围 :"; 41 cin >> range; 42 cout << "选择加减是否有正负数(y/n) : "; 43 cin >> zhengfu; 44 45 46 for (int i = 0; i < count; i++) 47 { 48 49 if (zhengfu == ‘n‘) 50 { 51 a[i] = rand() % range; //产生随机数 52 b[i] = rand() % range; 53 if (choice == ‘y‘) //选择是否有乘除; 54 { 55 c[i] = rand() % 4; //产生随机符号0到3分别代表四则运算 56 57 if (i == 0) //a[0],b[0]的特殊情况; 58 { 59 printf("%-4d", a[i]); 60 switch (c[i]) 61 { 62 case 0: 63 printf("+"); 64 break; 65 case 1: 66 printf("-"); 67 break; 68 case 2: 69 printf("*"); 70 break; 71 case 3: 72 printf("/"); 73 break; 74 } 75 printf("%4d =", b[i]); 76 for (j = 0; j < jiange; j++) 77 { 78 printf(" "); 79 } 80 } 81 else 82 { 83 for (int k = 0; k < i; k++) 84 { 85 if (a[k] == a[i] && b[k] == b[i] && c[k] == c[i]) 86 { 87 i--; 88 break; 89 } 90 else 91 { 92 if (k == i - 1) //比较到最后一个数时 93 { 94 printf("%-4d", a[i]); 95 switch (c[i]) 96 { 97 case 0: 98 printf("+"); 99 break; 100 case 1: 101 printf("-"); 102 break; 103 case 2: 104 printf("*"); 105 break; 106 case 3: 107 printf("/"); 108 break; 109 } 110 printf("%4d =", b[i]); 111 for (j = 0; j < jiange; j++) 112 { 113 printf(" "); 114 } 115 } 116 } 117 } 118 } 119 if ((i + 1) % num == 0) 120 printf("\n"); 121 } 122 else 123 { 124 c[i] = rand() % 2; //产生随机符号0到3分别代表四则运算 125 126 if (i == 0) 127 { 128 printf("%-4d", a[i]); 129 switch (c[i]) 130 { 131 case 0: 132 printf("*"); 133 break; 134 case 1: 135 printf("/"); 136 break; 137 } 138 printf("%4d =", b[i]); 139 for (j = 0; j < jiange; j++) 140 { 141 printf(" "); 142 } 143 } 144 else 145 { 146 for (int k = 0; k < i; k++) 147 { 148 if (a[k] == a[i] && b[k] == b[i] && c[k] == c[i]) 149 { 150 i--; 151 break; 152 } 153 else 154 { 155 if (k == i - 1) //比较到最后一个数时 156 { 157 printf("%-4d", a[i]); 158 switch (c[i]) 159 { 160 case 0: 161 printf("*"); 162 break; 163 case 1: 164 printf("/"); 165 break; 166 } 167 printf("%4d =", b[i]); 168 for (j = 0; j < jiange; j++) 169 { 170 printf(" "); 171 } 172 } 173 } 174 } 175 } 176 if ((i + 1) % num == 0) 177 printf("\n"); 178 } 179 } 180 else 181 { 182 if (choice == ‘y‘) //选择是否有乘除; 183 { 184 a[i] = rand() % (2 * range + 1) - range; //产生随机数 185 b[i] = rand() % (2 * range + 1) - range; 186 c[i] = rand() % 4; //产生随机符号0到3分别代表四则运算 187 188 if (i == 0) //a[0],b[0]的特殊情况; 189 { 190 printf("%-4d", a[i]); 191 switch (c[i]) 192 { 193 case 0: 194 printf("+"); 195 break; 196 case 1: 197 printf("-"); 198 break; 199 case 2: 200 printf("*"); 201 break; 202 case 3: 203 printf("/"); 204 break; 205 } 206 printf("%4d =", b[i]); 207 for (j = 0; j < jiange; j++) 208 { 209 printf(" "); 210 } 211 } 212 else 213 { 214 for (int k = 0; k < i; k++) 215 { 216 if (a[k] == a[i] && b[k] == b[i] && c[k] == c[i]) 217 { 218 i--; 219 break; 220 } 221 else 222 { 223 if (k == i - 1) //比较到最后一个数时 224 { 225 printf("%-4d", a[i]); 226 switch (c[i]) 227 { 228 case 0: 229 printf("+"); 230 break; 231 case 1: 232 printf("-"); 233 break; 234 case 2: 235 printf("*"); 236 break; 237 case 3: 238 printf("/"); 239 break; 240 } 241 printf("%4d =", b[i]); 242 for (j = 0; j < jiange; j++) 243 { 244 printf(" "); 245 } 246 } 247 } 248 } 249 } 250 if ((i + 1) % num == 0) 251 printf("\n"); 252 } 253 else 254 { 255 c[i] = rand() % 2; //产生随机符号0到3分别代表四则运算 256 257 if (i == 0) 258 { 259 printf("%-4d", a[i]); 260 switch (c[i]) 261 { 262 case 0: 263 printf("*"); 264 break; 265 case 1: 266 printf("/"); 267 break; 268 } 269 printf("%4d =", b[i]); 270 for (j = 0; j < jiange; j++) 271 { 272 printf(" "); 273 } 274 } 275 else 276 { 277 for (int k = 0; k < i; k++) 278 { 279 if (a[k] == a[i] && b[k] == b[i] && c[k] == c[i]) 280 { 281 i--; 282 break; 283 } 284 else 285 { 286 if (k == i - 1) //比较到最后一个数时 287 { 288 printf("%-4d", a[i]); 289 switch (c[i]) 290 { 291 case 0: 292 printf("*"); 293 break; 294 case 1: 295 printf("/"); 296 break; 297 } 298 printf("%4d =", b[i]); 299 for (j = 0; j < jiange; j++) 300 { 301 printf(" "); 302 } 303 } 304 } 305 } 306 } 307 if ((i + 1) % num == 0) 308 printf("\n"); 309 } 310 311 } 312 313 314 } 315 system("pause"); //暂停程序运行; 316 return 0; 317 }
感悟:
我觉本次编程我收获很多,让我认识到自己的很多不足,在本次中对算法的编辑等都不是很好,数据结构的掌握也不尽人意,希望自己有更大的提高,最后对代码的书写规范也不是很好,在后续的测试中还有望改进。
标签:
原文地址:http://www.cnblogs.com/mtant/p/4339879.html