fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <vector>
  5.  
  6. int numberOfConflicts(const std::string* input, const unsigned int& arrayLength);
  7. int main()
  8. {
  9. unsigned int n = 0;
  10. std::cin >> n;
  11. std::string* a;
  12. a = new std::string [n];
  13. for(int i = 0; i < n; i++)
  14. {
  15. std::cin >> a[i];
  16. }
  17. std::cout << numberOfConflicts(a, n) << std::endl;
  18. delete [] a;
  19. return 0;
  20. }
  21. int numberOfConflicts(const std::string* input, const unsigned int& arrayLength)
  22. {
  23. unsigned int result = 0;
  24. std::vector<std::string> duplicates;
  25. std::vector<std::string>::iterator it;
  26. for(int i = 0; i < arrayLength; i++)
  27. {
  28. it = find(duplicates.begin(), duplicates.end(), input[i]);
  29. for(int j = i + 1; j < arrayLength; j++)
  30. {
  31. if (input[i] == input[j] && it == duplicates.end())
  32. {
  33. result++;
  34. duplicates.push_back(input[i]);
  35. break;
  36. }
  37. }
  38. }
  39. return result;
  40. }
Success #stdin #stdout 0s 3280KB
stdin
Standard input is empty
stdout
0