fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n, pairs = 0;
  7. cin >> n;
  8. int sock[n];
  9. for(int i = 0; i < n; i++)
  10. cin >> sock[i];
  11.  
  12. for(int i = 0; i < n-1; ++i)
  13. { //selection sort
  14. for(int j = i+1; j < n; ++j)
  15. {
  16. if(sock[i] > sock[j])
  17. {
  18. int tmp = sock[j];
  19. sock[j] = sock[i];
  20. sock[i] = tmp;
  21. }
  22. }
  23. }
  24. //23466
  25. for(int i = 0; i < n-1; ++i) //number of pairs
  26. { cout<< "sock["<<i<<"] ="<< sock[i]<<" ,sock["<<i<<"+1] ="<<sock[i+1]<<endl;
  27. if(sock[i] == sock[i+1])
  28. {
  29. pairs++;
  30. }
  31. i++;
  32. }
  33. cout << pairs << endl;
  34. return 0;
  35. }
Success #stdin #stdout 0s 15240KB
stdin
5
43626
stdout
sock[0] =0  ,sock[0+1] =0
sock[2] =0  ,sock[2+1] =43626
1