kilolilo

Untitled

Oct 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int n,ch,s=0,a[n];
  6. cout<<"N = ";
  7. cin>>n;
  8. while (s<n){
  9. cout<<"a["<<s<<"]= ";
  10. cin>>ch;
  11. a[s]=ch;
  12. s++;
  13.  
  14. }
  15.  
  16. int max=a[0],min=a[0];
  17. int i=1;
  18. while (i<n ){
  19. if (a[i]>max ){
  20. max=a[i];
  21. }
  22. if (a[i]<min){
  23. min=a[i];
  24. }
  25. i++;
  26. }
  27. int g=max-min+1;
  28. int b[g];
  29. i=0;
  30. while (i<g){
  31. b[i]=0;
  32. i++;
  33. }
  34.  
  35. int e=0;
  36. while (e<n){
  37. int index=a[e]-min;
  38. b[index]+=1;
  39. e++;
  40. }
  41. int c[n],q=0,j=0,k;
  42. while (j<g){
  43. k=0;
  44. while (k<b[j]){
  45. c[q]=j+min;
  46. k++;
  47. q++;
  48. }
  49. j++;
  50. }
  51. cout<<" ";
  52. s=0;
  53. while(s < n){
  54. cout << c[s] << " ";
  55. s++;
  56. }
  57. cout << endl;
  58. }
Add Comment
Please, Sign In to add comment