fork(4) download
  1.  
  2. #include <iostream>
  3. #include <set>
  4. #include <cstdlib>
  5. #include <cstring>
  6. using namespace std;
  7.  
  8. bool contain(int* a, int b) {
  9. for (int i=0; i<10; i++)
  10. if(a[i] == b) return true;
  11.  
  12. return false;
  13. }
  14.  
  15. int compare (const void * a, const void * b)
  16. {
  17. return ( *(int*)a - *(int*)b );
  18. }
  19.  
  20. bool mymemcmp(int *a, int *b, int siz) {
  21. for(int i=0; i < siz; i++)
  22. if(a[i] != b[i]) return false;
  23.  
  24. return true;
  25. }
  26.  
  27. int main()
  28. {
  29. int bb=0;
  30. int tab[10];
  31. for(int i =0; i < 10; i++)
  32. cin >> tab[i];
  33.  
  34. qsort(tab,10,sizeof(int),compare);
  35.  
  36. for( int i0=2; i0 < 4999; i0++)
  37. for( int i1=2; i1 < 4999; i1++)
  38. {
  39. if(contain(tab,i0+i1))
  40. for( int i2=2; i2 < 4999; i2++)
  41. {
  42. if(contain(tab,i1+i2))
  43. if(contain(tab,i0+i2))
  44. for( int i3=2; i3 < 4999; i3++)
  45. {
  46. if(contain(tab,i1+i3))
  47. if(contain(tab,i2+i3))
  48. for( int i4=2; i4 < 4999; i4++){
  49. if(contain(tab, i0 + i4))
  50. if(contain(tab, i1 + i4))
  51. if(contain(tab, i2 + i4))
  52. if(contain(tab, i3 + i4))
  53. {
  54. int* newtab = new int[10];
  55. newtab[0] = i0+i4;
  56. newtab[1] = i1+i4;
  57. newtab[2] = i2+i4;
  58. newtab[3] = i3+i4;
  59. newtab[4] = i2+i3;
  60. newtab[5] = i1+i3;
  61. newtab[6] = i0+i3;
  62. newtab[7] = i0+i2;
  63. newtab[8] = i1+i2;
  64. newtab[9] = i0+i1;
  65. qsort(newtab,10, sizeof(int), compare);
  66. if(mymemcmp(newtab,tab,10)) {
  67. cout << i0 << endl;
  68. cout << i1 << endl;
  69. cout << i2 << endl;
  70. cout << i3 << endl;
  71. cout << i4 << endl;
  72. goto out;
  73. }
  74. delete newtab;
  75. }
  76.  
  77. }
  78. }
  79. }
  80. }
  81. out:
  82.  
  83. return 0;
  84. }
  85.  
  86.  
Success #stdin #stdout 0s 3032KB
stdin
10
12
16
10
6
12
18
8
14
14
stdout
2
4
6
8
10