ChameL1oN

Экзамен_Задача4

Dec 21st, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <locale>
  4. #include <iomanip>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. // КОЛ-ВО и ЗНАЧЕНИЯ ДВУХ упорядоченных ПО УБЫВАНИЮ одномерных массивов ХРАНЯТСЯ в текстовике.
  10. // Получить из них 3-ий упорядоченный ПО УБЫВАНИЮ. БЕЗ СОРТИРОВКИИ
  11.  
  12. ifstream f("ishod.txt", ios::in);
  13. int count1, count2;
  14. void Print_mas(int* mass, int n){ //Функция для печати матрицы
  15. int i = 0;
  16.  
  17. while (i < n){
  18. cout << setw(6) << mass[i] << " ";
  19. i++;
  20. }
  21.  
  22. cout << endl;
  23.  
  24. }
  25.  
  26. int* form_mas(int count){
  27. int* massive = new int[count];
  28. int a = 0;
  29.  
  30. while (a < count){
  31. f >> massive[a];
  32. a++;
  33. }
  34. return massive;
  35. }
  36.  
  37. void massive3(int* mass1, int* mass2){
  38. int i = 0, j = 0, a = 0;
  39. int* mass3 = new int[count1 + count2];
  40. while (a < (count1 + count2)){
  41. if (mass1[i] > mass2[j]){
  42. mass3[a] = mass1[i];
  43. i++;
  44. }
  45. else{
  46. mass3[a] = mass2[j];
  47. j++;
  48. }
  49. a++;
  50. }
  51. cout << "А вот блять и третий массив без всякой там сортировки" << endl;
  52. Print_mas(mass3, count1 + count2);
  53. }
  54.  
  55. void main()
  56. {
  57. setlocale(LC_ALL, "rus");
  58. f >> count1;
  59. f >> count2;
  60. int* mass1 = form_mas(count1);
  61. cout << "Исходный массив : " << endl;
  62. Print_mas(mass1, count1);
  63. int* mass2 = form_mas(count2);
  64. cout << "Исходный массив : " << endl;
  65. Print_mas(mass2, count2);
  66. massive3(mass1, mass2);
  67. f.close();
  68. }
Advertisement
Add Comment
Please, Sign In to add comment