Advertisement
Jade39

Untitled

Oct 16th, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. // 2lab.cpp: определяет точку входа для консольного приложения.
  2. /* #8. Дана последовательность натуральных чисел {aj}j=1...n (n<=40).
  3.     Упорядочить элементы последовательности до первого числа,
  4.     не содержащего цифру 5, (включительно) по невозрастанию, а
  5.     остальные элементы - по неубыванию.
  6. */
  7.  
  8. #include "stdafx.h"
  9. #include <iostream>
  10. #include <string>
  11. #include <stdlib.h>
  12.  
  13. using namespace std;
  14. FILE *stream;
  15.  
  16. int Check_task(int x) {
  17.     int b=0;
  18.     while(x){
  19.         if(x%10==5 ) return 1;
  20.         x/=10;
  21.     }
  22.     return 0;
  23. }
  24.  
  25.  
  26. int main()
  27. {   int a[40];
  28.     int i,j,k,n,tmp;
  29.     i=0;
  30.     k=-1;
  31.     freopen_s( &stream, "input.txt", "r" , stdin );
  32.     freopen_s( &stream, "output.txt", "w" , stdout );
  33.  
  34.  
  35.     while (cin>>a[i]){
  36.            
  37.         if (Check_task(a[i])==0) {
  38.             k=i;
  39.            
  40.         }
  41.         i++;
  42.     }
  43.     n=i;
  44.         for(i=0;i<=k;i++){
  45.         tmp=a[i];
  46.         j=i-1;
  47.             while(j>=0 && a[j]<tmp){
  48.             a[j+1]=a[j];
  49.             j--;
  50.             }
  51.         a[j+1]=tmp;
  52.         }
  53.  
  54.         for(i=k+1;i<n;i++){
  55.          for(j=i+1;j<n;j++){
  56.                 if(a[i]>a[j]) {
  57.                     tmp=a[i];
  58.                     a[i]=a[j];
  59.                     a[j]=tmp;
  60.                 }
  61.          }
  62.         }
  63.    
  64.    
  65.     for (i=0;i<n;i++)
  66.      {
  67.          cout<<a[i]<<" ";
  68.      }
  69.  
  70. return 0;  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement