Advertisement
tankian202

Untitled

Dec 4th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <fstream>
  4. #include <string.h>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. int main()
  10. { int i=0,j=0,eleje=1,vege,k,h=0;
  11. char seg[258]=" ",s[258],ss[100][258];
  12.  
  13. gets(s);
  14. strcat(seg,s);
  15. strcat(seg," ");
  16. strcpy(s,seg);
  17. for(i=1;s[i]!='\0';i++)
  18. {
  19.  
  20. if(s[i-1]==' ' and s[i]!=' ')eleje=i;
  21.  
  22. if(s[i]==' ' and s[i-1]!=' ')
  23. {
  24. strncpy(ss[j],s+eleje,i-eleje);
  25. ss[j][i-eleje]='\0';
  26. j++;
  27. }
  28. }
  29. seg[0]='\0';
  30. int ok=1;
  31. char se[258];
  32. while(ok==1)
  33. {
  34. ok=0;
  35. for(i=0;i<j-1;i++)
  36. if(strcmp(ss[i],ss[i+1])==1)
  37. { ok=1;
  38. strcpy(se,ss[i]);
  39. strcpy(ss[i],ss[i+1]);
  40. strcpy(ss[i+1],se);
  41. }
  42. }
  43.  
  44. i=0;
  45. while(i<j-1)
  46. if(strcmp(ss[i],ss[i+1])==0)
  47. {
  48. for(k=i+1;k<j-1;k++)
  49. strcpy(ss[k],ss[k+1]);j--;
  50. }
  51. else i++;
  52.  
  53. for(i=0;i<j;i++)
  54. cout<<ss[i]<<endl;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement