Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<cstring>
  4.  
  5. using namespace std;
  6. ifstream fin("sortarecuvinte1.in");
  7. ofstream fout("sortarecuvinte1.out");
  8.  
  9. void sort(char A[][31], int n)
  10. {
  11. for(int i=2; i<=n; i++)
  12. {
  13. for(int j=i; j>=2; j--)
  14. {
  15. if(strcmp(A[j-1],A[j])==1)
  16. {
  17. char s[31];
  18. strcpy(s,A[j]);
  19. strcpy(A[j],A[j-1]);
  20. strcpy(A[j-1],s);
  21. }
  22. }
  23. }
  24. }
  25.  
  26. char A[201][31];
  27. int main()
  28. {
  29. int cnt=0;
  30. while(fin>>A[++cnt])
  31. true;
  32. cnt--;
  33. sort(A,cnt);
  34. for(int i=1; i<=cnt; i++)
  35. fout<<A[i]<<endl;
  36.  
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement