Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 2lab.cpp: определяет точку входа для консольного приложения.
- /* #8. Дана последовательность натуральных чисел {aj}j=1...n (n<=40).
- Упорядочить элементы последовательности до первого числа,
- не содержащего цифру 5, (включительно) по невозрастанию, а
- остальные элементы - по неубыванию.
- */
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <stdlib.h>
- using namespace std;
- FILE *stream;
- int Check_task(int x) {
- int b=0;
- while(x){
- if(x%10==5 ) return 1;
- x/=10;
- }
- return 0;
- }
- int main()
- { int a[40];
- int i,j,k,n,tmp;
- i=0;
- k=-1;
- freopen_s( &stream, "input.txt", "r" , stdin );
- freopen_s( &stream, "output.txt", "w" , stdout );
- while (cin>>a[i]){
- if (Check_task(a[i])==0) {
- k=i;
- }
- i++;
- }
- n=i;
- for(i=0;i<=k;i++){
- tmp=a[i];
- j=i-1;
- while(j>=0 && a[j]<tmp){
- a[j+1]=a[j];
- j--;
- }
- a[j+1]=tmp;
- }
- for(i=k+1;i<n;i++){
- for(j=i+1;j<n;j++){
- if(a[i]>a[j]) {
- tmp=a[i];
- a[i]=a[j];
- a[j]=tmp;
- }
- }
- }
- for (i=0;i<n;i++)
- {
- cout<<a[i]<<" ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement