Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. int apcar(char *s, int x)
  7. {
  8. int cnt = 0;
  9. char *p = strchr(s,x);
  10. while(p != NULL)
  11. {
  12. cnt ++ ;
  13. p = strchr(p + 1, x);
  14. }
  15.  
  16. return cnt;
  17. }
  18.  
  19. int main()
  20. {
  21. char s[256], *p, v[101][16];
  22. cin.getline(s, 256);
  23. int n = 0;
  24. p = strtok(s," ");
  25. while(p)
  26. {
  27. bool gasit = false;
  28. for(int i = 1; i <= n ; i ++)
  29. if(strcmp(v[i],p) == 0)
  30. gasit = true;
  31. if(!gasit)
  32. strcpy(v[++n], p);
  33.  
  34. p = strtok(NULL, " ");
  35.  
  36.  
  37. }
  38. for(int i = 1; i< n; i ++)
  39. for(int j = i + 1; j <= n; j ++)
  40. if(strcmp(v[i],v[j]) > 0)
  41. {
  42. char t[16];
  43. strcpy(t,v[i]);
  44. strcpy(v[i], v[j]);
  45. strcpy(v[j], t);
  46. }
  47.  
  48. for(int i =1; i <= n ; i ++)
  49. cout << v[i] << '\n';
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement