fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. string a[100];
  7. int i,n;
  8. cin >> n; // no. of words in a sentence
  9.  
  10. // loop to enter n words
  11. for ( i=0;i<n;i++ )
  12. cin >> a[i];
  13.  
  14. // sort the input string
  15. sort(a,a+n);
  16.  
  17.  
  18. for ( i=0;i<n;i++ )
  19. {
  20. if ( a[i]!=a[i+1] ) // check for duplicates
  21. cout << a[i] << " ";
  22. }
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 2824KB
stdin
4
hi hello hi hi
stdout
hello hi