Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. class Ascii
  8. {
  9. public:
  10. int cod;
  11. public:
  12. friend ostream & operator << (ostream &out, const Ascii &c);
  13. friend istream & operator >> (istream &in, Ascii &c);
  14. bool operator < ( const Ascii& val ) const {
  15. return cod < val.cod;
  16. }
  17. };
  18.  
  19. struct Asciigreater
  20. {
  21. bool operator()( const Ascii& lx, const Ascii& rx ) const {
  22. return lx.cod < rx.cod;
  23. }
  24. };
  25.  
  26. ostream & operator << (ostream &out, const Ascii &c)
  27. {
  28. out << char(c.cod) << " ";
  29. return out;
  30. }
  31.  
  32. istream & operator >> (istream &in, Ascii &c)
  33. {
  34. in >> c.cod;
  35. return in;
  36. }
  37.  
  38. int main()
  39. {
  40. Ascii c1;
  41. int v[100];
  42. int n=0;
  43. ifstream f("in.txt");
  44. ofstream g1("out1.txt");
  45. while(f >> c1){
  46. g1 << c1;
  47. v[n++]=c1.cod;
  48. }
  49. int aux;
  50. for(int i=0;i<n;i++)
  51. for(int j=i+1;j<n;j++){
  52. if(v[i]<v[j]){
  53. aux=v[i];
  54. v[i]=v[j];
  55. v[j]=aux;
  56. }
  57. }
  58. ofstream g2("out2.txt");
  59. n--;
  60. while(n>=0){
  61. g2 << char(v[n]) << " ";
  62. n--;
  63. }
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement