Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Лаба-7
- Вариант-20.
- Дана последовательность натуральных чисел {aj}j=1...n (n<=10000).
- Если в последовательности есть хотя бы одно число, все цифры которого одинаковы, упорядочить последовательность по неубыванию.
- #include <limits.h>
- #include <iostream>
- using namespace std;
- bool is_equal_digit(int a){
- int max=0;
- int d=a%10;
- while(a>0){
- if(d!=a%10)return false;
- a/=10;
- }
- return true;
- }
- int main(){
- int n=0;
- cin>>n;
- int a[n];
- bool equal=false;
- for(int i=0;i<n;i++){
- cin>>a[i];
- if(is_equal_digit(a[i]))equal=true;
- }
- if(equal)
- for(int i=0;i<n-1;i++){
- for(int j=i+1;j<n;j++){
- if(a[i]>a[j]){
- int t=a[i];
- a[i]=a[j];
- a[j]=t;
- }
- }
- }
- for(int i=0;i<n;i++){
- cout<<a[i]<<" ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement