Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. /*Лаба-7
  2. Вариант-20.
  3. Дана последовательность натуральных чисел {aj}j=1...n (n<=10000).
  4. Если в последовательности есть хотя бы одно число, все цифры которого одинаковы, упорядочить последовательность по неубыванию.
  5.  
  6. #include <limits.h>
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. bool is_equal_digit(int a){
  11. int max=0;
  12. int d=a%10;
  13. while(a>0){
  14. if(d!=a%10)return false;
  15. a/=10;
  16. }
  17. return true;
  18. }
  19.  
  20.  
  21. int main(){
  22. int n=0;
  23. cin>>n;
  24. int a[n];
  25. bool equal=false;
  26. for(int i=0;i<n;i++){
  27. cin>>a[i];
  28. if(is_equal_digit(a[i]))equal=true;
  29. }
  30. if(equal)
  31. for(int i=0;i<n-1;i++){
  32. for(int j=i+1;j<n;j++){
  33. if(a[i]>a[j]){
  34. int t=a[i];
  35. a[i]=a[j];
  36. a[j]=t;
  37. }
  38. }
  39. }
  40. for(int i=0;i<n;i++){
  41. cout<<a[i]<<" ";
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement