Advertisement
Guest User

llh

a guest
Nov 28th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. #include <QtCore/QCoreApplication>
  2. #include<iostream>
  3. #include<windows.h>
  4. using namespace std;
  5.  
  6. void ArrRandom(int ar[], int *pEnd, int modul);
  7. int character(int *pEnd,int ar[]);
  8. void newArr(int ar[],int *pEnd,int n);
  9. void SortArray(int ar[],int *pEnd);
  10. bool SortMod(int x1, int x2);
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14. QCoreApplication a(argc, argv);
  15. cout<<"Введите ограничение чисел ";
  16. int ar[80],modul, *pEnd=ar,*p;
  17. cin>>modul;
  18. cout<<endl;
  19. cout<<"Введите количество чисел массива ";
  20. int N;
  21. cin>>N;
  22. pEnd+=N;
  23. cout<<"Массив случайных чисел ";
  24. ArrRandom(ar,pEnd,modul);
  25. cout<<endl<<endl<<"Характеристика массива"<<endl;
  26. cout<<"Рiзниця мiж сумами парних та непарних чисел ";
  27. cout<<character(pEnd,ar);
  28. cout<<endl<<endl<<"Задайте на скiльки змiстити масив "<<endl;
  29. int n;
  30. cin>>n;
  31. //newArr(ar,pEnd,n);
  32. //for (int *p=ar;p<pEnd;p++)
  33. // cout<<*p<<" ";
  34. cout<<endl<<"Сортування за ускладненим правилом"<<endl;
  35. cout<<"Спочатку непарнi за зростанням, потiм парнi числа за спаданням ";
  36. SortArray(ar,pEnd);
  37. for(int *p=ar;p<pEnd;p++)
  38. cout<<*p<<" ";
  39.  
  40.  
  41. return a.exec();
  42. }
  43. void ArrRandom(int ar[], int *pEnd, int modul){
  44. for (int *p=ar;p<pEnd;p++){
  45. *p = rand()%modul;
  46. cout<<*p<<" ";}
  47. }
  48.  
  49. int character(int *pEnd,int ar[]){
  50. int sum1=0,sum2=0;
  51. int *s1=&sum1,*s2=&sum2;
  52. for(int *p=ar;p<pEnd;p++)
  53. if(*p%2==0) *s1+=*p;
  54. else *s2+=*p;
  55. int rizn=*s1-*s2;
  56. return rizn;
  57. }
  58.  
  59. void SortArray(int ar[],int *pEnd)
  60. {
  61. for(int *p1=ar; p1<pEnd-1; p1++)
  62. for(int *p2=p1; p2<pEnd; p2++)
  63. if(SortMod(*p1,*p2))
  64. swap(*p1,*p2);
  65. }
  66.  
  67. bool SortMod(int x1, int x2)
  68. {
  69. if(x1%2 && x2%2)return x1>x2;
  70. else if(!(x1%2) && !(x2%2))return x1<x2;
  71. else return abs(x1%2)<abs(x2%2);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement