Advertisement
Guest User

sortcif2

a guest
Feb 25th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4. ifstream fin ("sortcif2.in");
  5. ofstream fout ("sortcif2.out");
  6. int v[101],cif[101],n,aux;
  7. bool ok=1;
  8. int pcif(int a)
  9. {
  10. while(a>10)
  11. {
  12. a/=10;
  13. }
  14. return a;
  15. }
  16. int main()
  17. {
  18. fin>>n;
  19. for(int i=1 ; i<=n ; i++)
  20. {
  21. fin>>v[i];
  22. cif[i]=pcif(v[i]);
  23. }
  24. do
  25. {
  26. ok=0;
  27. for(int i=1 ; i<=n ; i++)
  28. {
  29. if(cif[i]<cif[i+1])
  30. {
  31. ok=1;
  32. aux=v[i];
  33. v[i]=v[i+1];
  34. v[i+1]=aux;
  35. aux=cif[i];
  36. cif[i]=cif[i+1];
  37. cif[i+1]=aux;
  38. }
  39. }
  40. }while(ok);
  41. for(int i=n ; i>=1 ; i--)
  42. fout<<v[i]<<" ";
  43.  
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement