fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <ctime>
  4. #include <climits>
  5.  
  6. #define rangeMin 0
  7. #define rangeMax 500
  8. #define SIZE 500
  9.  
  10. using namespace std;
  11.  
  12. void print(const map<int, int>& map)
  13. {
  14. cout << "Answer: " << endl;
  15. cout << INT_MIN << " ~ " << rangeMin << endl;
  16. for(auto iter = map.begin(); iter != map.end(); ++iter)
  17. {
  18. cout << iter->second << " ";
  19. }
  20. cout << endl;
  21. cout << rangeMax + 1 << " ~ " << INT_MAX << endl;
  22. }
  23.  
  24. void exclusive(map<int, int>& map, int array[], int size)
  25. {
  26. for(int i = 0; i < size; ++i)
  27. {
  28. int key = array[i];
  29. auto iter = map.find(key);
  30. if(iter != map.end())
  31. {
  32. map.erase(iter);
  33. }
  34. }
  35. }
  36.  
  37. void randomArray(int array[], int size)
  38. {
  39. cout << "Array: " << endl;
  40. for(int i = 0; i < size; ++i)
  41. {
  42. array[i] = rangeMin + rand() % (rangeMax + 1);
  43. cout << array[i] << " ";
  44. }
  45. cout << endl;
  46. }
  47.  
  48. int main(int argc, char* argv[])
  49. {
  50. srand(time(0));
  51. int array[SIZE] = { 0 };
  52. map<int, int> map;
  53. for(int i = rangeMin; i <= rangeMax; ++i)
  54. {
  55. map.insert(make_pair(i, i));
  56. }
  57.  
  58. randomArray(array, SIZE);
  59. exclusive(map, array, SIZE);
  60. print(map);
  61.  
  62. return 0;
  63. }
Success #stdin #stdout 0s 3232KB
stdin
Standard input is empty
stdout
Array: 
292 202 153 448 486 97 192 318 125 477 128 124 465 398 319 206 247 210 140 389 479 15 67 44 79 20 115 73 238 408 156 29 109 310 224 341 153 416 158 279 138 286 149 349 430 469 55 423 178 442 312 157 457 125 448 35 146 62 109 130 216 265 160 71 321 384 412 475 45 317 500 431 349 148 279 279 363 334 201 288 275 259 191 231 385 138 13 277 200 122 407 416 133 313 233 201 443 144 175 235 461 421 165 310 68 444 335 432 278 35 219 299 41 410 277 172 47 290 449 494 158 101 155 291 161 388 492 103 278 413 338 486 79 249 295 148 193 376 326 217 157 44 15 198 200 292 370 494 328 64 233 486 413 388 23 73 21 261 423 299 421 7 284 500 256 325 394 195 200 219 412 358 9 428 55 209 466 172 449 294 483 181 25 395 315 295 214 336 56 384 135 223 137 419 222 393 491 363 335 190 81 246 47 91 420 350 46 386 268 496 426 250 176 197 392 238 239 105 73 41 235 208 264 372 374 232 11 364 94 346 53 176 91 348 13 258 444 59 143 211 54 315 207 478 258 98 215 497 451 34 37 185 243 301 57 363 280 68 226 374 414 25 296 251 119 55 8 62 115 398 19 416 459 227 139 217 71 354 460 21 389 498 207 378 44 10 487 70 325 459 191 238 230 233 235 350 289 491 158 404 388 425 319 347 151 205 310 222 58 15 491 193 12 197 317 304 454 303 374 278 7 311 15 238 44 497 87 333 487 492 236 121 416 301 214 313 5 23 282 311 38 272 250 298 469 314 348 422 363 468 446 371 279 461 108 323 203 195 155 190 433 137 57 95 438 271 408 190 40 189 0 325 207 497 122 175 310 216 343 173 184 34 43 209 241 151 31 445 92 186 381 271 69 438 366 6 208 20 443 248 456 189 319 163 186 188 84 242 404 174 415 334 208 204 42 450 101 73 394 440 5 274 211 74 458 323 328 412 343 270 406 299 460 224 462 392 412 45 133 316 219 295 149 428 245 439 377 347 11 16 32 264 36 490 338 494 313 165 405 402 182 310 447 388 280 408 279 192 200 412 254 165 453 403 339 198 87 462 291 99 478 323 109 13 313 447 253 372 359 404 273 287 460 220 174 240 374 453 432 320 
Answer: 
-2147483648 ~ 0
1 2 3 4 14 17 18 22 24 26 27 28 30 33 39 48 49 50 51 52 60 61 63 65 66 72 75 76 77 78 80 82 83 85 86 88 89 90 93 96 100 102 104 106 107 110 111 112 113 114 116 117 118 120 123 126 127 129 131 132 134 136 141 142 145 147 150 152 154 159 162 164 166 167 168 169 170 171 177 179 180 183 187 194 196 199 212 213 218 221 225 228 229 234 237 244 252 255 257 260 262 263 266 267 269 276 281 283 285 293 297 300 302 305 306 307 308 309 322 324 327 329 330 331 332 337 340 342 344 345 351 352 353 355 356 357 360 361 362 365 367 368 369 373 375 379 380 382 383 387 390 391 396 397 399 400 401 409 411 417 418 424 427 429 434 435 436 437 441 452 455 463 464 467 470 471 472 473 474 476 480 481 482 484 485 488 489 493 495 499 
501 ~ 2147483647