Advertisement
a53

CuvinteComune

a53
Jan 26th, 2021
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. char v[100][30];
  7. int n;// n este numarul de cuvinte
  8.  
  9. void cauta(char *p)
  10. {
  11. int i;
  12. for(i=0;i<n;i++)
  13. if(strcmp(v[i],p)==0)
  14. return ;
  15. strcpy(v[n],p);
  16. n++;
  17. }
  18.  
  19. int main()
  20. {
  21. char s1[256],s[256],*p;
  22. int i,ok;
  23. cin.getline(s,256);
  24. cin.getline(s1,256);
  25. for(i=0;i<strlen(s);i++)
  26. if(s[i]>='A' && s[i]<='Z')
  27. s[i]+=32;
  28. for(i=0;i<strlen(s1);i++)
  29. if(s1[i]>='A' && s1[i]<='Z')
  30. s1[i]+=32;
  31. p=strtok(s," ");
  32. while(p)
  33. {
  34. if(strstr(s1,p))
  35. cauta(p);
  36. p=strtok(NULL," ");
  37. }
  38. do
  39. {
  40. ok=1;
  41. for(i=0;i<n-1;i++)
  42. if(strcmp(v[i],v[i+1])>0)
  43. {
  44. swap(v[i],v[i+1]);
  45. ok=0;
  46. }
  47. }
  48. while(ok==0);
  49. for(i=0;i<n;i++)
  50. cout<<v[i]<<'\n';
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement